So I recently tried getting a string as an input in a bash script which looked a little something like this:
#!/bin/bash
while getopts s: flag
do
case "${flag}" in
s|--sample) sample=${OPTARG}
echo $sample
;;
esac
done
The credit for most of this code goes to baeldung at 2.2.
If I try to run this code, it works, but only if I use -s
. If I use --sample
, it just echo's ample
. Is there an easy way around this