Checking if PWD contains directory name

bash, shell

Solution

You can use BASH regex for this:

[[ "$PWD" =~ somedir ]] && echo "PWD has somedir"

OR using shell glob:

[[ "$PWD" == *somedir* ]] && echo "PWD has somedir"

Problem

I want to find out if the PWD contains a certain directory name in it, it should be able to test it being anywhere in the output. For example I have structure paths like `public/bower_components/name/` and also have paths which are just `public`. I want to test because the contents of the folder `name` move into the public folder and the `bower_components` folder is removed. Thanks

Original source