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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With