I have a bash script and I want to check if a string is in a list. Like: string = "Hello World!", List=("foo", "bar"). Python example:
if name in list: # Another way -> if name in ["foo", "bar"]
# work to do
else:
sys.exit(1)
Thank you!
I have a bash script and I want to check if a string is in a list. Like: string = "Hello World!", List=("foo", "bar"). Python example:
if name in list: # Another way -> if name in ["foo", "bar"]
# work to do
else:
sys.exit(1)
Thank you!
There are a number of ways, the simplest I see is:
WORD_LIST="one two three"
MATCH="two"
if echo $WORD_LIST | grep -w $MATCH > /dev/null; then
command
else
exit 1
fi