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:
#!/bin/sh
WORD_LIST="one two three"
MATCH="twox"
if echo "$WORD_LIST" | grep -qw "$MATCH"; then
echo "found"
else
echo "not found"
exit 1
fi