Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add in space escape for $PWD

I want to use

ln -s $PWD ~/mylinkname

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

I believe the solution should be simply but I searched over cannot find answer.

Do you know how to solve this problem?

Thanks a lot.

like image 697
songyy Avatar asked Sep 02 '12 09:09

songyy


People also ask

How do you escape space in file path?

Also try using the Grave Accent Character (`) PowerShell uses the grave accent (`) character as its escape character. Just add it before each space in the file name. (You'll find this character above the Tab key and below the Esc key on your keyboard.)

How do you escape space in shell?

The shell will interpret that backslash as an escape of the space. The result will be that the command will not break the argument. The other way to escape space in a path is to enclose the path in quotes, which indicates to the executable that everything between the quotes is one argument.

How do you escape space in bash script?

In a bash script, we can escape spaces with \ .

How do I add a space in Linux terminal?

Well, there are two approaches: Using escape character, i.e., “\<space>” Using apostrophes or quotation marks.


2 Answers

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

To prevent this, quote any arguments that have spaces, eg:

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

If the filename 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"
like image 175
ronalchn Avatar answered Sep 30 '22 15:09

ronalchn


ln -s "$PWD" "$HOME/mylinkname"

should do it.

like image 24
Lev Levitsky Avatar answered Sep 30 '22 15:09

Lev Levitsky