An example of how to use getopts in bash
问题 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