I am trying to use getopts to parse some command-line arguments in bash version 4.2.45. Unfortunately when I run this script with -r1 apple -r2 banana -n hello -k 56 I do not get any output for r1 or r2. e.g.
./script.sh -r1 apple -r2 banana -n hello -k 56
hello 56
Below is script.sh
read1=
read2=
name=
ks=
outdir=
threads=
while getopts "r1:r2:n:k:o:t" OPTION
do
case $OPTION in
r1) read1="$OPTARG" ;;
r2) read2="$OPTARG" ;;
n) name="$OPTARG" ;;
k) ks="$OPTARG" ;;
o) outdir="$OPTARG" ;;
t) threads="$OPTARG" ;;
esac
done
echo $read1 $read2 $name $ks
When I change r1->r and r2->x then I see:
apple banana hello 56
as I expected. Are digits really not allowed as options, or is there something else I am missing here?