Last active
October 4, 2020 04:27
-
-
Save 0ncorhynchus/7620768954c94fc5c47554f6c111f996 to your computer and use it in GitHub Desktop.
a tiny command line argument parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Usage: | |
# source entrance "arg1 arg2 arg3" $* | |
# | |
readonly program=$(basename $0) | |
readonly args=($1) | |
shift 1 | |
if [ $# -ne ${#args[@]} ]; then | |
echo >&2 "Usage: ${program} $(IFS=' '; echo ${args[*]^^})" | |
exit 1 | |
fi | |
for arg in ${args[@]}; do | |
eval "readonly ${arg}=$1" | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment