Created
December 2, 2021 14:05
-
-
Save pavithran215/82af0333a45a2b20b4f629d57788b951 to your computer and use it in GitHub Desktop.
Example implementation of getOpts in shell script
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
while getopts "asmd" options; | |
do | |
case $options in | |
a) | |
echo addition | |
d=$2 | |
f=$3 | |
echo $(( $d+$f )) | |
;; | |
s) | |
echo subraction | |
d=$2 | |
f=$3 | |
echo $(( $d-$f )) | |
;; | |
m) | |
echo multiplication | |
d=$2 | |
f=$3 | |
echo $(( $d*$f )) | |
;; | |
d) | |
echo division | |
d=$2 | |
f=$3 | |
echo $(( $d/$f )) | |
;; | |
*) | |
echo "invalid option $OPTARG" | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment