nimo
September 25, 2009, 10:54am
1
Hi everyone,
I have never wrote script in csh before, but I need to add only few lines to an existing one. I tried to use the bash standard syntax, and it did not work. So, I attempted to use csh syntax, and it is not working. Can someone help please:
switch ( $Return_Code )
case 0: echo "SUCCSS"
breaksw
cae -1: echo "FAIL"
breaksw
endsw
I also tried:
if ( $Return_Code == 0 )
then echo "SUCCESS"
else echo "FAIL"
endif
Good. Keep it that way!
Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful
but I need to add only few lines to an existing one. I tried to use the bash standard syntax, and it did not work. So, I attempted to use csh syntax, and it is not working.
Bash and csh syntax are very different.
You will probably be better off translating the entire script to a Bourne-type syntax, POSIX or bash.
nimo
September 25, 2009, 11:17am
3
What I meant is that the script is csh and already exists. I need to corrct the few lines shown in my message. Thanks.
drl
September 25, 2009, 5:32pm
4
Hi.
Follow the advice from cfajohnson whenever you can.
If I had to modify the csh script, I would use:
#!/usr/bin/env tcsh
# @(#) s1 Demonstrate csh case statement on separate line.
echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version "=o" tcsh
echo
set Return_Code=0
switch ( $Return_Code )
case 0:
echo "SUCCSS"
breaksw
# cae -1: echo "FAIL"
case -1:
echo "FAIL"
breaksw
default:
echo " Error in settings."
breaksw
endsw
exit 0
producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
tcsh 6.14.00
SUCCSS
Each case selector must be alone on the line. Remember the importance of experimentation -- best wishes ... cheers, drl