I want to call myscript
file in this way:
$ ./myscript -s 45 -p any_string
or
$ ./myscript -h #should display help
$ ./myscript #should display help
My requirements are:
getopt
here to get the input arguments
- check that
-s
exists, if not return an error
- check that the value after the
-s
is 45 or 90
- check that the
-p
exists and there is an input string after
- if the user enters
./myscript -h
or just ./myscript
then display help
I tried so far this code:
#!/bin/bash
while getopts "h:s:" arg; do
case $arg in
h)
echo "usage"
;;
s)
strength=$OPTARG
echo $strength
;;
esac
done
But with that code I get errors. How to do it with Bash and getopt
?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…