Skip to content

Instantly share code, notes, and snippets.

@jason51285128
Created June 17, 2019 03:58
Show Gist options
  • Save jason51285128/468635d96cac028f1bd65e14da5ffff7 to your computer and use it in GitHub Desktop.
Save jason51285128/468635d96cac028f1bd65e14da5ffff7 to your computer and use it in GitHub Desktop.
use ##short option in bash ##
#!/bin/bash
help()
{
cat << HERE
usage: ./opt.sh -a {value} -b {value} -c {value} -d {value} -h
HERE
}
while getopts "a:b:c:d:h" arg
do
case $arg in
a)
echo "option a is $OPTARG"
;;
b)
echo "option b is $OPTARG"
;;
c)
echo "option c is $OPTARG"
;;
d)
echo "option d is $OPTARG"
;;
h)
help
exit 0
;;
?)
help
exit 1
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment