Answers for "substring match in shell script"

1

shell: search a substring in another string

# Search for a substring in another string using wildcard

string='My long string'
substr='My long'

# Note: the wildcard character (*) is outside the double qoute ("")
if [[ "$string" == *"$substr"* ]]; then
  echo "Found substring!"
fi
Posted by: Guest on April-20-2022
2

substring in shell script

STR="birthday-091216-pics"
SUBSTR=$(echo $STR | cut -d'-' -f 2)
echo $SUBSTR
Posted by: Guest on October-29-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language