Skip to main content
Add exit 0 and a note about proper option processing
Source Link
tripleee
  • 191.6k
  • 37
  • 317
  • 367

It doesn't have to be harder than this.

case $1 in
 -[h?]|] | --help)
    cat <<-____HALP
        Usage: ${0##*/} [ --help ]
        Outputs a friendly help message if you can figure out how.
____HALP 
 ;;       exit 0;;
esac

If you use getopts for option processing, use that to identify the option; but the action is going to look more or less similar (and IMNSHO getopts doesn't really offer anything over a simple while ... shift loop).

It doesn't have to be harder than this.

case $1 in
 -[h?]|--help)
    cat <<-____HALP
        Usage: ${0##*/} [ --help ]
        Outputs a friendly help message if you can figure out how.
____HALP ;;
esac

It doesn't have to be harder than this.

case $1 in
 -[h?] | --help)
    cat <<-____HALP
        Usage: ${0##*/} [ --help ]
        Outputs a friendly help message if you can figure out how.
____HALP 
        exit 0;;
esac

If you use getopts for option processing, use that to identify the option; but the action is going to look more or less similar (and IMNSHO getopts doesn't really offer anything over a simple while ... shift loop).

Source Link
tripleee
  • 191.6k
  • 37
  • 317
  • 367

It doesn't have to be harder than this.

case $1 in
 -[h?]|--help)
    cat <<-____HALP
        Usage: ${0##*/} [ --help ]
        Outputs a friendly help message if you can figure out how.
____HALP ;;
esac