Q:

substring if statement variable shell script

#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'
if [[ "$STR" == *"$SUB"* ]]; then
  echo "It's there."
fi
1
#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'

case $STR in

  *"$SUB"*)
    echo -n "It's there."
    ;;
esac
1
if echo "$string" | grep 'foo'; then
  echo "It's there!"
fi
0
if [ $string ?? 'foo' ]; then
  echo "It's there!"
fi
0
string="My string"
0

New to Communities?

Join the community