0

I have a bash script called unions.sh:

_show_help ()
{
    echo "$0 [-t time]"
    echo
    echo "-CARD [num]"
    echo "   card number"
    echo
    exit 0
}


_cleanup ()
{
    echo Cleaning Up..
    exit 5
}

trap _cleanup 0 1 2 5 6
until [ -z "$1" ]
do
    case "$1" in
    "--CARD")
        shift
        if [ -z "$1" ]; then
            _fatal_error "--CARD must have an argument"
        fi
        _card="$1"
        ;;
    "-h"|"--help")
        _show_help
        ;;
    esac
    shift
done

When I ran ./unions.sh -h the output was

./unions.sh [-t time]

-CARD [num]
   card number

Cleaning Up..

I have a doubt here. when I used the exit in the help function it called the _cleanup function. I have the same exit in the _cleanup function. Why that should not again call the _cleanup function?

Jolta
  • 2,620
  • 1
  • 29
  • 42
  • Because it doesn't trap that one. – 123 Feb 16 '16 at 09:53
  • Why it doesn't trap. It trapped the one in the _show_help. Why not now – praveen kumar Feb 16 '16 at 10:01
  • The traps aren't called every time `exit` is called, but just prior to the shell exiting. The `exit` call is idempotent in that sense; you can call it during the exit process, but the shell still only exits once. – chepner Feb 16 '16 at 15:07

0 Answers0