Skip to main content
fixed esac statement and clarified unreliability statement
Source Link

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; eascesac 

ThatUnfortunately that will also spot "command this-here" as having "-h".

Normally you'd use getopts to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc]) echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done shift (($OPTIND - 1)) # General (non-option) arguments are now in "$@" 

Etc.

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; easc 

That will spot "command this-here" as having "-h".

Normally you'd use getopts to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc]) echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done shift (($OPTIND - 1)) # General (non-option) arguments are now in "$@" 

Etc.

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; esac 

Unfortunately that will also spot "command this-here" as having "-h".

Normally you'd use getopts to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc]) echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done shift (($OPTIND - 1)) # General (non-option) arguments are now in "$@" 

Etc.

Minor extensions and fixups. Nothing critical this time.
Source Link
Jonathan Leffler
  • 759.4k
  • 145
  • 961
  • 1.3k

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; easc 

That will spot "command this-here""command this-here" as having "-h"-h".

Normally you'd use getopts to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc]) echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done shift (($OPTIND - 1)) # General (non-option) arguments are now in "$@" 

Etc.

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; easc 

That will spot "command this-here" as having "-h".

Normally you'd use getopts to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc]) echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done 

Etc.

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; easc 

That will spot "command this-here" as having "-h".

Normally you'd use getopts to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc]) echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done shift (($OPTIND - 1)) # General (non-option) arguments are now in "$@" 

Etc.

getopts is a command, not a function - and fix alignment of echo commands
Source Link
Jonathan Leffler
  • 759.4k
  • 145
  • 961
  • 1.3k

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; easc 

That will spot "command this-here" as having "-h".

Normally you'd use getopts() to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc])   echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done 

Etc.

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; easc 

That will spot "command this-here" as having "-h".

Normally you'd use getopts() to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc])   echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done 

Etc.

It is modestly complex. The quickest way is also unreliable:

case "$*" in (*-h*) echo "Has -h";; easc 

That will spot "command this-here" as having "-h".

Normally you'd use getopts to parse for arguments that you expect:

while getopts habcf: opt do case "$opt" in (h) echo "Has -h";; ([abc]) echo "Got -$opt";; (f) echo "File: $OPTARG";; esac done 

Etc.

Source Link
Jonathan Leffler
  • 759.4k
  • 145
  • 961
  • 1.3k
Loading