Jump to content

C-Shell Scripting

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Dreamcatcher

Dreamcatcher

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
Hello, Well I am working for first time in C-shell so please be "kind" with my potentially idiot question... My job is to make a script that according the date (sysdate) checks the logs... I stuck in the if syntax ... I don't know why but this simple code that checks the first argument of the user is not working..

Here is the code...


 9         if ($1=="s") then

10                 echo "seconds";

11         else if ($1=="d") then 

12              echo "days";

13         else if ($1=="h") then

14                echo "hours";

15         else if ($1=="m") then

16               echo "minutes";

17         else

18                 echo "Wrong argument";

19         endif

This is a testing part through which i try to solve the problem (that's why it has so many echo)... it finishes with this error...
if: Expression Syntax. at the first if.

Thanx in advance...
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity." -- Dennis Ritchie

#2
untitled_1

untitled_1

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts
The problem is with your if statement structure, I assume you are using bash?
Try follow:
If[ "$variable1" = "$variable2" ] ; then
Your code
else
Your code
fi

This is the general structure of bash if statement...

#3
ReignInChaos

ReignInChaos

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
You noted that you were using c shell? Is this correct? If so I would assume you have #!/bin/csh on line 1 (or w/e C shell you are using). However, you do have a mistake in your expression syntax. You need spaces in the expressions. For instance, the first one should be

if ( $1 == "s" ) then
  echo "seconds";
....

Once you add those, it will work correctly, counting on no other mistakes in other parts.

Hope this helps.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users