So I'm writing a script that takes in arguments given from the shell. The last argument I'm using as a tag to tell my script, via if statements, to do one thing or another. A sample input would be:
script.scr infile.txt outfile.txt F
The "F" at the end there I expect to be one of two tags "F" or "F.p". In my script, just to give an error if the tags are neither of two things, I have an if statment like:
if ($#argv = 3)
set tags = $argv[3]
else set tags = ""
if ( $tags != "F" || $tags != "F.p" ) then
echo Invalid tag entry.
exit
endif
The problem is that the echo and exit will execute even if a correct tag is given. I use similar if statements to perform different actions on those files based on the tag given. For example:
if ($tags == "F") then
...
else if ($tags == "F.p") then
...
else if ($tags == "") then
...
endif
I'm sure that there's just a little thing I'm doing wrong, and any help is appreciated.
Haha, you're right I was thinking of &&. Now my only other problem is that second part. Where $tags == "F" and the like don't execute properly. Using -vx will even show "if ( F == F ) then" but it won't execute the code block even though the statement is clearly true.
Something wrong with the structure here, should be: if ( ) then ... else ... endif:
csh has bad structure control, here the result is nearly unpredictable.
Then, $#argv = 3 is an assignment, you want a comparison.
Then, assignments should be var=value, no spaces!
if ($#argv == 3) then
set tags=$argv[3]
else
set tags=""
endif
Last but not least, you should quote variables references like "$var" whenever possible: