Denis Kutlubaev
Denis Kutlubaev

Reputation: 16124

Escape spaces in Bash folder variable

I am trying to create a variable in Bash to access fastly to some folders and save it to my bash_profile script file. This is how script looks like

Documents=~/Documents
Apps=~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications

After running the script the $Documents variable works and $Apps doesn't. It tells:

-bash: cd: /Users/myusername/Library/Application: No such file or directory

This is the path to the folder:

/Users/myusername/Library/Application Support/iPhone Simulator/5.1/Applications

How should I escape spaces? I use Vim and I type "cd $Apps".

Upvotes: 1

Views: 4733

Answers (2)

F Corthay
F Corthay

Reputation: 31

You can also quote the string and not use the backslash character: Apps='~/Library/Application Support/iPhone Simulator/5.1/Applications' cd "$Apps"

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798606

The spaces are fine; it's your command that's wrong.

cd "$Apps"

Upvotes: 11

Related Questions