In csh, use
exit [n]
Suppose you want to write a script named readable that returns a 0 if a file is readable and a 1 if the file is not readable.
if [ -r "$1" ] then
exit 0
else
exit 1
endif
You pass readable a single argument, which is a filename. If the file is a readable file, the return code is a 0; otherwise, a 1 is returned. Now in your parent shell you can use the $? ($status-csh) variable to test whether the file is readable are not. For example, your parent shell might look like this: readable somefile
if [ $? ] then
echo "Processing the file"
...
else
echo "Cannot read the file"
endif
This provides you with the capability to tell whether a child shell script completed with or without errors.
Note: this useful text is from http://alasir.com/
Aucun commentaire:
Enregistrer un commentaire