sh script problem with capturing return code

Fbsd8 fbsd8 at a1poweruser.com
Tue Jan 8 21:30:51 UTC 2013


I can not get the return code from mtree to control
the displaying of a error message.

The mtree at the end of the script does function correctly
because I can tell from the printed output.

When mtree prints comments saying "extra" that means the directory being 
read does not match the specification file. return code should be Not 
equal to zero.

And when they do match IE: no mtree comments printed, that should be a 
return code of zero.

I tried 2 different ways to capture the return code to no joy.
What I am doing wrong?

#! /bin/sh
flavor="/a/mtree.std"
echo "flavor = ${flavor}"
/bin/cat  << EOF |
/set type=dir uname=root gname=wheel
.
etc     ignore
..
root    ignore
..
usr
home    ignore
..
local
etc     ignore
..
..
..
..
EOF

  mtree -d -u -p "${flavor}"  || \
    echo "Error invalid directories in flavor ${flavor}."

#mtree -d -p "${flavor}"
#[ $? -eq 0 ] || \
#  echo "Error invalid directories in flavor ${flavor}."
echo "return = $?"




More information about the freebsd-questions mailing list