Handling parameters in Bash
Short Mode Only :
<br></br>
#!/bin/bash<br></br>
while getopts :a:b:c opt #define options here : at the front supress error for unknown options<br></br>
do<br></br>
case $opt in<br></br>
a) ARG1="${OPTARG}"<br></br>
if [ "$ARG1" == "" ]<br></br>
then<br></br>
print_usage $0<br></br>
else<br></br>
echo "option a is " $ARG1<br></br>
fi ;;<br></br>
b) TYPE="$OPTARG";;<br></br>
p) PRICES="$OPTARG";;<br></br>
?) print_usage $0<br></br>
exit 1;;<br></br>
esac<br></br>
done<br></br>
echo "Balances: "$BAL<br></br>
echo "Type: "$TYPE<br></br>```
!/bin/bash
options=":hzx-:"
usage()
{
echo "You can display the Usage options here"
}
while getopts "$options" params; do
case "${params}" in
-)
case "${OPTARG}" in
option1)
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
echo "Parsing option: '--${OPTARG}', value: '${val}'" >&2;
;;
option1=)
val=${OPTARG#=}
opt=${OPTARG%=$val}
echo "Parsing option: '--${opt}', value: '${val}'" >&2
;;
help)
echo "usage: $0 -zx --option1= --option2="
;;
*)
if [ "$OPTERR" = 1 ] && [ "${options:0:1}" != ":" ]; then
echo "Unknown option --${OPTARG}" >&2
usage
fi
;;
esac;;
z)
val="${!OPTIND}";
echo "Parsing option: '-${params}' value:$val" >&2
;;
*)
if [ "$OPTERR" != 1 ] || [ "${options:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
usage
fi
;;
h)
echo "usage: $0 [-v] [--loglevel[=]]" >&2
exit 2
;;
esac
done```