Shell Programming 159
endif
produces this error:
foo: Undefined variable.
To get the script to “do the right thing,” you have to resort to a script
that looks like this:
#!/bin/csh
unset foo
if (! $?foo ) then
echo foo was unset
set foo
else if ( "$foo" = "You lose" ) then
echo $foo
endif
[Notice the need to ‘set foo’ after we discovered that it was unset.]
Clear, eh?
Error Codes and Error Checking
Our programming example glossed over how the file command reports an
error back to the shell script. Well, it doesn’t. Errors are ignored. This
behavior is no oversight: most Unix shell scripts (and other programs as
well) ignore error codes that might be generated by a program that they
call. This behavior is acceptable because no standard convention exists to
specify which codes should be returned by programs to indicate errors.
Perhaps error codes are universally ignored because they aren’t displayed
when a user is typing commands at a shell prompt. Error codes and error
checking are so absent from the Unix Canon that many programs don’t
even bother to report them in the first place.
Date: Tue, 6 Oct 92 08:44:17 PDT
From: Bjorn Freeman-Benson <[email protected]>
Subject: It’s always good news in Unix land
To: UNIX-HATERS
Consider this tar program. Like all Unix “tools” (and I use the word
loosely) it works in strange and unique ways. For example, tar is a
program with lots of positive energy and thus is convinced that noth-
ing bad will ever happen and thus it never returns an error status. In