I'm using the getopts
command to process the flags in my bash script, using the structure found in this answer: https://stackoverflow.com/a/21128172/2230446
#!/bin/bash
t_flag='30'
print_usage() {
printf "Usage: ..."
}
while getopts 't:' flag; do
case "${flag}" in
t) t_flag="${OPTARG}" ;;
*) print_usage
exit 1 ;;
esac
done
echo "${t_flag}"
I run the script with the following command:
./test.sh -t dog cat fish
My goal is to extract cat fish
to a variable so I can use it in the rest of the script, similar to how the t_flag
was extracted to a variable.