Add 'bash/argument_parsing.bash'

This commit is contained in:
daryl
2022-05-26 16:08:22 +09:30
parent cc5b71d536
commit e37dc43718

View File

@@ -0,0 +1,30 @@
#!/bin/bash
while [[ $# -gt 0 ]]; do
case "$1" in
-a|--all)
# set option a/all
shift # and get the next argument
;;
-h|--help)
# display help
exit # because we want to stop
;;
-z|--zooper)
zooper=$2 # grab the NEXT argument after the -z|--zooper
shift # throw away the -z|--zooper
shift # and throw away its value that we've also used
;;
-*|--*)
echo "We've found an unknown option: $1"
# show help if you like
shift
break # stop parsing but allow script to continue, if that's useful
;;
*)
echo "I don't know how we got here, it shouldn't happen. Should have handled the args or hit the unknowns option just above."
exit
;;
esac
done