Hi.
It looks like you are using the
csh family and you wish to know how to run a command and test the exit status in an
if. Most people agree that members of the csh family are not good for scripting because of technical drawbacks and flaws. The Bourne shell family is considered superior for scripting.
However, if you must use
csh, you can use braces to obtain the exit status of a command:
Code:
#!/bin/csh
# @(#) s2 Demonstrate csh braces: run command, test exit status.
# Create a scratch file if one does not exist.
touch t1
echo
if ( { ls t1 } ) then
echo " command ls succeeded."
else
echo " command ls FAILED."
endif
# Remove file.
rm t1
echo
if ( { ls t1 } ) then
echo " command ls succeeded."
else
echo " command ls FAILED."
endif
exit $status