Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parse command line arguments with getopts
#!/bin/bash
function one() {
echo "one > $1"
}
function two() {
echo "two > $1"
}
while getopts ":x:y:" opt; do
case ${opt} in
x ) one $OPTARG;
;;
y ) two $OPTARG;
;;
esac
done
###########################
# ./test.sh -x "1" -y "2"
# one > 1
# two > 2
###########################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment