I want to make sure the value of a variable (STATE
) is part of a list (ALL_STATES
).
#!/usr/bin/bash
STATE='somevalue'
ALL_STATES=( lirum larum loeffelstiel )
echo state id is: "${STATE}"
echo all states are: "${ALL_STATES[@]}"
while ${STATE} not in ${ALL_STATES} ; do
echo ${STATE} needs a valid value
read -p "please provide the state ID: " STATE
done
echo state id is: "${STATE}"
I am getting ./test_while_loop.sh: line 8: somevalue: command not found
though. So there seems to be something wrong with my condition, just what?
https://shellcheck.net
, a syntax checker, or installshellcheck
locally. Make usingshellcheck
part of your development process. – waltinator Oct 24 '23 at 15:35path
, one has to check their shell's manual anyway if they want to avoid clashing with names their shell holds special. The rest of the stuff about capitalization styles (e.g.snake_case
vs.CamelCase
) is just opinion-based... – ilkkachu Oct 25 '23 at 14:12