Table of Contents
*Tags*: command line parameters
How to handle command swithes in scripts. Here are the examples from the simplest to the most powerful one.
[ "x$1" = "x-l" ] && {
log_url=T
shift
}[ "x$1" = "x-t" ] && {
file_title=$2
shift 2
}[ ${1+T} ] || fhelp
mto=$1
shift
mfm=$1
shift
[ ${1+T} ] && { msg=$1; shift; }while :; do
case "$1" in
-s*) fl_sys=T ;; # system file listing
-p*) shift; prefix="$1" ;; # for the beg'ing of filename
-s*) shift; surfix="$1" ;; # for end of filename, bfr .tgz
*) break ;;
esac
shift
doneuse getopt, but really suggest using the previous method for compatibility reasons.
set -- `getopt "clhstx" "$@"` || fhelp
while :; do
case "$1" in
-s) fl_sys=T ;; # system file listing
-c) fl_csh=T ;; # csh/tcsh system file listing
-p*) shift; prefix="$1" ;; # for the beg'ing of filename
-t*) shift; surfix="$1" ;; # for end of filename, bfr .tgz
--) shift; break ;;
esac
shift
doneand can be called with combined switch such as '-sc..t'.