Skip to content

Instantly share code, notes, and snippets.

@pavithran215
Created December 2, 2021 14:05
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 pavithran215/82af0333a45a2b20b4f629d57788b951 to your computer and use it in GitHub Desktop.
Save pavithran215/82af0333a45a2b20b4f629d57788b951 to your computer and use it in GitHub Desktop.
Example implementation of getOpts in shell script
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