Solved

C Shell nested IF statement

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now