[lug] return code

Tkil tkil at scrye.com
Thu Jun 6 12:03:29 MDT 2002


>>>>> "Hugh" == Hugh Brown <hugh at vecna.com> writes:

Hugh> if the return code in $?, the return code of rpm or the return
Hugh> code of the redirect to /dev/null

"return code of the redirect" doesn't make any sense.  It's not a
separate program; it's a feature performed by bash.  If bash can't do
the redirect, it should complain and then not launch the program at
all.  A bit of experimentation shows that "$?" does get set to
non-zero for a failed redirect, at least with "echo":

| $ echo "hi" > /dev/null ; echo $?
| 0
| $ echo "hi" > /cant-write-here ; echo $?
| bash: /cant-write-here: Permission denied
| 1

This can also be shown with perl, with an extra print to stderr to
show that the program is never executed at all:

| $ perl -lwe 'print STDERR "err"; print STDOUT "out";'
| err
| out
| $ echo $?
| 0
|
| $ perl -lwe 'print STDERR "err"; print STDOUT "out";' > /dev/null
| err
| $ echo $?
| 0
|
| $ perl -lwe 'print STDERR "err"; print STDOUT "out";' > /cant-write-here
| bash: /cant-write-here: Permission denied
| $ echo $?
| 1

In your particular case, there's an ambiguity; according to

   http://www.rpm.org/hintskinks/returncode/

the return code from rpm is the number of packages that failed to
install.  If exactly one failed, and you're doing a redirect that
might also fail, $? is ambiguous.

I'd suggest just capturing non-fancy output and processing it after
the fact to figure out what happened.

t.



More information about the LUG mailing list