Solved

C Shell nested IF statement

Posted on 2011-03-02
3
3,221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

732 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