Amarjit Dhillon
Amarjit Dhillon

Reputation: 2816

export alias in ~.bash_profile for a path having a filename containing space

I am trying to add an alias in bash_profile in Mac. Actual path of file I am trying to create alias is

amar@admin:~/Library/Application Support/com.bohemiancoding.sketch3/Plugins 

$pwd

/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins

I have tried 2 options

Option # 1

export sketch="/Users/amar/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins"

This has error like

amar@admin:~$ echo $sketch
/Users/amar/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins
amar@admin:~$ cd $sketch
-bash: cd: /Users/amar/Library/Application\: No such file or directory

Option # 2

export sketch="/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins"

this shows error like

amar@admin:~$ echo $sketch
/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins
amar@admin:~$ cd $sketch
-bash: cd: /Users/amar/Library/Application: No such file or directory

Issue is near this file name Application Support

Upvotes: 0

Views: 1487

Answers (1)

that other guy
that other guy

Reputation: 123550

You have to quote the variable when you expand it:

sketch="/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins"
cd "$sketch"

Quoting is not optional and there's nothing you can do to avoid it.

Upvotes: 3

Related Questions