"bash getopts" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "bash getopts" answered properly. Developers are finding an appropriate answer about bash getopts related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like bash getopts. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on bash getopts. 

bash getopts

By SantinoSantino on Mar 09, 2021
#!/bin/bash

usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1; }

while getopts ":s:p:" o; do
    case "${o}" in
        s)
            s=${OPTARG}
            ((s == 45 || s == 90)) || usage
            ;;
        p)
            p=${OPTARG}
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

if [ -z "${s}" ] || [ -z "${p}" ]; then
    usage
fi

echo "s = ${s}"
echo "p = ${p}"
Example runs:

$ ./myscript.sh
Usage: ./myscript.sh [-s <45|90>] [-p <string>]

$ ./myscript.sh -h
Usage: ./myscript.sh [-s <45|90>] [-p <string>]

$ ./myscript.sh -s "" -p ""
Usage: ./myscript.sh [-s <45|90>] [-p <string>]

$ ./myscript.sh -s 10 -p foo
Usage: ./myscript.sh [-s <45|90>] [-p <string>]

$ ./myscript.sh -s 45 -p foo
s = 45
p = foo

$ ./myscript.sh -s 90 -p bar
s = 90
p = bar

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on bash getopts can get a collection of related answers to their query. Programmers need to enter their query on bash getopts related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about bash getopts for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of bash getopts while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "bash getopts". Visit this developer's friendly online web community, CodeProZone, and get your queries like bash getopts resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "bash getopts"

View All Whatever queries

Whatever queries related to "bash getopts"

Browse Other Code Languages

CodeProZone