Skip to content

Instantly share code, notes, and snippets.

@0ncorhynchus
Last active October 4, 2020 04:27
Show Gist options
  • Save 0ncorhynchus/7620768954c94fc5c47554f6c111f996 to your computer and use it in GitHub Desktop.
Save 0ncorhynchus/7620768954c94fc5c47554f6c111f996 to your computer and use it in GitHub Desktop.
a tiny command line argument parser
#!/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