Created
March 22, 2012 20:36
-
-
Save JiriChara/2163848 to your computer and use it in GitHub Desktop.
Processing options and parameters with getopts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# processing options and parameters with getopts | |
while getopts :ab:cd opt | |
do | |
case "$opt" in | |
a) echo "Found the -a option";; | |
b) echo "Found the -b option, with value $OPTARG";; | |
c) echo "Found the -c option";; | |
d) echo "Found the -d option";; | |
*) echo "Unknown option: $opt";; | |
esac | |
done | |
shift $[ $OPTIND - 1 ] | |
count=1 | |
for param in "$@" | |
do | |
echo "Parameter $count: $param" | |
count=$[ $count + 1 ] | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment