Script Arguments and getopts
Scripts read arguments with $1 and $@. shift removes the first one. getopts parses flags like -v and -n NAME.
Example
set -- -v -n Ada extra
verbose=0
while getopts "vn:" opt; do
case $opt in v) verbose=1;; n) name=$OPTARG;; esac
done
shift $((OPTIND - 1))
echo "v=$verbose name=$name rest=$*"Result
v=1 name=Ada rest=extra
Exercise
Drop the first argument.
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.