How to add space to mileage for $ PWD

I want to use

ln -s $PWD ~/mylinkname

But the problem I am facing is that my current path has space (therefore ln cannot execute correctly).

I believe that the solution should be simple, but I searched, I can not find the answer.

Do you know how to solve this problem?

Many thanks.

+5
source share
2 answers

If your argument has spaces, it will treat each space delimited part as a separate argument.

To prevent this, specify any arguments with spaces, for example:

ln -s "$PWD" "$HOME/my link name with spaces"

If the file name has quotes, you can also escape it with a backslash

ln -s "$PWD" "$HOME/my link name with spaces and this quote\""

Instead of $ HOME you can use:

ln -s "$PWD" ~/"my link name with spaces"
+7
source
ln -s "$PWD" "$HOME/mylinkname"

must do it.

+5
source

All Articles