I'm writing a bash script that has optional flags but also an input.
I can't get the input as $1 because when flags are present the input is shifted.
So for example if I run script.sh test then $1 will be equal to test.
But if I run script.sh -b test then $1 will be equal to -b.
while getopts 'bh' flag; do
case "${flag}" in
b) boxes= 'true' ;;
h) echo "options:"
echo "-h, --help show brief help"
echo '-b add black boxes for monjaro'
;;
*) error "Unexpected option ${flag}" ;;
esac
done
echo $1;
The amount of flags I have is not set, I know I will add more in the future.
How can I consistently get the first non-flag value?