Solved

C Shell nested IF statement

Posted on 2011-03-02
3
3,145 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to configure linux OS using Ubuntu 7 69
UNIX Script. Send email if failure 8 56
Post Clonezilla image restore issue 6 61
Pass stdin text to Python subprocess 3 47
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

713 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