So I have a program (say, programA), that will give me an output, for example: yes, no, maybe, probably, possibly, impossible, banana.
I want to make a script that will do something, whatever it is, based on that output. Let's say I only need to account for yes, maybe and banana.
So far what I would do, is use case like so:
case $program_output in
yes) echo "good word: $program_output" ;;
maybe) echo "good word: $program_output" ;;
banana) echo "good word: $program_output" ;;
*) echo "bad word: $program_output" ;;
esac
But recently I was fiddling with the if statement, and found out I can do this faster like so:
if [[ "yesmaybebanana" =~ ${program_output} ]]; then
echo "good word: ${program_output}"; else echo "bad word: ${program_output}";
fi
Is there any reason why I should not use the if statement for this?
This is a case where $program_output cannot have spaces in it, and it's a limited list of words it can output.