• Unix / linux programs

    From Weatherby,Gerard@21:1/5 to All on Sat Jan 28 19:40:04 2023
    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.

    #!/bin/bash
    if [ $# -lt 2 ]; then
    echo "Usage: $0 [tar] [directory to compare]"
    fi
    tar --diff -f $1 $2 2>/dev/null
    r=$?
    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
    else
    echo "Other error $r"
    fi

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)