Solved

C Shell nested IF statement

Posted on 2011-03-02
3
3,056 Views
Last Modified: 2012-06-27
Hi I have a CSH script that is giving me problems.

Basically if 5 == 5 the script asks to delete the files yes or no. That part works. But what doesn't is when 4 ==5.
It complains about "DEL: Undefined variable."
The way it is setup it should just skip down to echo " 4 doesn't equal 5"
For some reason it is going to the next else if and continuing the script.  

Can someone tell me why this is happening? It seems like a very simple thing to do.

Thanks
Fixitben

set autodelete=y

                if(4 == 5)then
                        echo "Do you wish to delete old job files (y/n)?"
                        set DEL=$<
                        if($DEL == "n")then
                                 exit 1
                        else if($DEL == "y")then
                                 $autodelete="y"
                        else
                                 echo "Cannot continue"
                                 exit 1
                        endif
                else
                        echo "4 doesn't equal 5"
               endif

Open in new window

0
Comment
Question by:fixitben
3 Comments
 
LVL 9

Accepted Solution

by:
AriMc earned 500 total points
ID: 35021944
Try adding some spaces like this. Also you probably want to set autodelete to "y" with
"set autodelete..."


#!/bin/csh
set autodelete=y

if (4 == 5) then
   echo "Do you wish to delete old job files (y/n)?"
   set DEL=$<

   if ($DEL == "n") then
      exit 1
   else if ($DEL == "y") then
      set autodelete="y"
   else
      echo "Cannot continue"
      exit 1
   endif
else
    echo "4 doesn't equal 5"
endif

Open in new window

0
 
LVL 13

Expert Comment

by:Superdave
ID: 35022067
Try
 set DEL $<

(without the =)
0
 
LVL 7

Author Closing Comment

by:fixitben
ID: 35022239
That was it. The spaces. Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question