Solved

C Shell nested IF statement

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

Industry Leaders: 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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
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.

705 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