Example of script usage
./myscript --p 1984 --n someName
#!/bin/bash
while getopts :npr opt
do
case $opt in
n ) echo name= ??? ;;
p ) echo port= ??? ;;
r ) echo robot= "Something" ;;
? ) echo "Useage: -p [#]" ;;
esac
done
How to I access the argument following the command option?
Moreover, if i type: ./myscript --p 1985 I would like to know how ot echo 1985 back and work with that argument.
In bash, see
help getopts: “When an option requires an argument, getopts places that argument into the shell variable OPTARG.”I’m sure you could google around for a solution to parse options in bash. Here’s a couple minutes’ effort:
And a test,