7. Passing of script parameters
7.1.shift command
Brief introduction:
Shift n Shifts the parameter position to the left n bits at a time
Example
#!/bin/bashusage () { echo "usage: ' basename ' filenames"}totalline=0# The following statement $# the number of arguments if [$#-lt 2]then usagefiwhile [$#-ne 0]do line= ' cat $ | wc-l ' echo ' $1:${line} ' totalline=$ [$totalline + $line]shiftdoneecho '----- ----"echo" Total:${totalline} "
7.2.getopts
Brief introduction:
Get multiple command-line arguments
Example
#!/bin/bashall=falsehelp=falsefile=falseverbose=falsewhile getopts Ahfvc:optiondo case $OPTION in a) All=true echo "All is $ALL" ;; h) help=true echo "Help is $HELP" ;; f) File=true echo "FILE is $FILE" ;; V) verbose=true echo "VERBOSE is $VERBOSE" ;; c) echo "C value is $c" ;; \?) c= $OPTARG echo "' basename $ '-[a H F v]-[C value] file" ;; Esacdone
7.3.shift and getopts can be passed with more than 9 parameters
Shell Programming Basics Tutorial 7--script parameter delivery