Horje
bash substring test Code Example
bash substring test
#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'
if [[ "$STR" == *"$SUB"* ]]; then
  echo "It's there."
fi
Source: linuxize.com
checking if a substring exists in a string bash
string='Haystack';

if [[ $string =~ "Needle" ]]
then
   echo "It's there!"
fi
bash substring test
#!/bin/bash

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

if grep -q "$SUB" <<< "$STR"; then
  echo "It's there"
fi
Source: linuxize.com
bash substring test
#!/bin/bash

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

if [[ "$STR" =~ .*"$SUB".* ]]; then
  echo "It's there."
fi
Source: linuxize.com
bash substring test
#!/bin/bash

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

case $STR in

  *"$SUB"*)
    echo -n "It's there."
    ;;
esac
Source: linuxize.com




Shell

Related
linux command disk speed test Code Example linux command disk speed test Code Example
react-native-router-flux Code Example react-native-router-flux Code Example
discord components python install Code Example discord components python install Code Example
linux set alternatives /etc/alternatives Code Example linux set alternatives /etc/alternatives Code Example
change php version ubuntu Code Example change php version ubuntu Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
13