Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Created June 13, 2020 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rojenzaman/680c039285ec733bc1ac5f8ebec760af to your computer and use it in GitHub Desktop.
Save rojenzaman/680c039285ec733bc1ac5f8ebec760af to your computer and use it in GitHub Desktop.
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