#!/bin/bash # # alice shell script # # Enhanced version of alice script from _Learning_the_Bash_Shell_ (O'Reilly) # Demonstrates use of positional parameters ( $@ , $* , $1 , etc). # Invoke it with aruments, for example `alice in wonderland` # # if [ -z "$1" ] # if there were no parameters then ... then echo "Usage: alice in wonderland" echo " This script demonstrates the use of positional parameters in shell scripts." echo " Invoke it with arguments, for example \`alice in wonderland\`, to see the use" echo ' of the variables $@ $* $0 $1 $2 $3 $4 $# and $IFS in shell scripting.' echo " " # # else echo "\$@: $@" # $@ contains all of the positional parameters except $0 echo "\$*: $*" # $* is like $@ except uses $IFS to seperate elements instead of just spaces echo 'change $IFS with IFS=,' IFS=, # change $IFS to demonstrate difference beteen $@ and $* echo "\$@: $@" echo "\$*: $*" # echo "\$0 \$1 \$2 \$3 \$4: $0 $1 $2 $3 $4" echo "\`basename \$0\` \$1 \$2 \$3 \$4: `basename $0` $1 $2 $3 $4" echo "\${0##*/} \$1 \$2 \$3 \$4: ${0##*/} $1 $2 $3 $4" # ${0##*/} has similar effect to basename echo "\$# gives the number of arguments: $# " # $# gives number of arguments passed to script fi