Search for username substring in pwd string

This question already has an answer here:


ANSWERS:


There are two things, what you search for, and what you search in. You're mixing the two in your examples.

if [[ "$USER_NAME" == *"$PWD"* ]]; then
           ^------swap----^

And this greps in the file named by the contents of PWD clearly won't work, because PWD is a directory, not a file:

grep "$USER_NAME" "$PWD"


 MORE:


 ? how to find file name has a string x or not
 ? Linux /bin/sh check if string contains X
 ? How to find and replace special chars within a string in zsh
 ? Shell script to check if a string contains something
 ? UNIX shell script do loop execute commands
 ? String comparison in bash. [[: not found
 ? String comparison in bash. [[: not found
 ? String comparison in bash. [[: not found
 ? String comparison in bash. [[: not found
 ? How to find substring inside a string (or how to grep a variable)?