Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 510 Bytes

partial-string-matching-in-bash-scripts.md

File metadata and controls

23 lines (18 loc) · 510 Bytes

Partial String Matching In Bash Scripts

To compare two strings in a bash script, you will have a snippet of code similar to the following:

if [[ $(pwd) == "/path/to/current/directory" ]]
then
  echo "You are in that directory";
fi

You may only want to do a partial string match. For this, you can use the * wildcard symbol.

if [[ $(pwd) == *"directory"* ]]
then
  echo "You are in that directory";
fi

source