0

This question already has an answer here:

I'm trying to compare the current working directory's path with my home directory's path.

user@machine:~$ echo $PWD
/home/user
user@machine:~$ if ["$PWD" = "/home/user"]; then echo True; else echo False; fi
bash: [/home/user: No such file or directory
False
user@machine:~$ if ["$PWD" = "whatever"]; then echo True; else echo False; fi
bash: [/home/user: No such file or directory
False

I expected it to print True in the second command and False in the third, while not printing bash: [/home/user: No such file or directory. Why is it printing this and how do I get it to work as I wanted to?

marked as duplicate by Jeff Schaller, Kusalananda shell Feb 20 at 14:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    There must be spaces between [ or ] and the string. Try if [ "$PWD" = "/home/user" ]; then... It is printing the error message because it tries to find a command [/home/user instead of [ followed by argument /home/user. – Bodo Feb 20 at 13:57
0

you're appending [ to $PWD.

try:

user@machine:~$ if [ "$PWD" = "/home/user" ];

Not the answer you're looking for? Browse other questions tagged or ask your own question.