Any idea what is wrong with this script? I am trying to check to see if the username is part of the present working directory file path. I have included two different implementations of the same thing, and neither of them work.
#!/bin/bash
USER_NAME=$(whoami)
if [[ "$USER_NAME" == *"$PWD"* ]]; then
echo $PWD
else
echo "not found"
fi
case "$USER_NAME" in
*$PWD*) echo $PWD ;;
esac
Also, this does not work either:
grep "$USER_NAME" "$PWD"
However, this works:
echo "$PWD" | grep "$USER_NAME"
Any idea what is going on here?
EDIT: This does not work either:
if [[ *"$PWD"* == "$USER_NAME" ]]; then
echo "found"
else
echo "not found"
fi
or even this:
if [[ $PWD == $USER_NAME ]]; then
echo "found"
else
echo "not found"
fi
or any other combination of *
or quotes that I have tried so far.
EDIT2:
finally got it, have to use this:
if [[ $PWD == *$USER_NAME* ]]; then
echo "found"
else
echo "not found"
fi