Mailing List Archive

Unix / linux programs
The Unix convention is 0 means everything went well, and non-zero means something else happened. Here?s a contrived example of a bash wrapper around GNU tar. By contrived I mean it works but I would not use it in practice ? I?d just use tar directly or use the Python tarfile module if I wanted finer grain control of the process.

if [ $# -lt 2 ]; then
echo "Usage: $0 [tar] [directory to compare]"
tar --diff -f $1 $2 2>/dev/null
if [ $r -eq 0 ]; then
echo $1 has $2 in it, unmodified
elif [ $r -eq 1 ]; then
echo $1 does not have $2 in it unmodified
elif [ $r -eq 2 ]; then
# maybe do more tests here?
echo There is a problem with $1 or with $2
echo "Other error $r"

Incidentally, I found the man page installed on Ubuntu20.04 for tar is out of date. tar returns 64 if doesn?t like the command line arguments. Nothing works until it is tested.