$myscript.sh -host blah -user blah -pass blah
I want to pass arguments into it.
I\'m used to doing $1
, $2
,
Here is a simple way to handle both long and short options:
while [[ $1 == -* ]]; do
case "$1" in
-h|--help|-\?) show_help; exit 0;;
-v|--verbose) verbose=1; shift;;
-f) if (($# > 1)); then
output_file=$2; shift 2
else
echo "-f requires an argument" 1>&2
exit 1
fi ;;
--) shift; break;;
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
esac
done
From How can I handle command-line arguments (options) to my script easily?