Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-03-2012, 05:47 PM   #1
LQ Newbie
Registered: Jan 2011
Posts: 1

Rep: Reputation: 0
Export path with spaces - escape characters and quotes not working - Ubuntu 10.04

Hi Linux Questions,

For some reason, escape characters and quotes don't seem to work anymore when trying to export a new path variable. Observe a few lines from my .bash_profile file.

export DESKTOP="/home/abhay/Desktop"
export RCGSHARE="/home/abhay/Desktop/rcgshare"
export MCSA="$DESKTOP/GA\ and\ MCSA\ Projects/mcsa\ project"
export WORKSPACE="$DESKTOP/workspace"

$DESKTOP, $RCGSHARE, and $WORKSPACE all work correctly. They have no spaces

$MCSA gives:
abhay@jcmaxwell:~/Desktop/workspace$ $MCSA
bash: /home/abhay/Desktop/GA\: No such file or directory

Now we'll try

export MCSA="$DESKTOP/'GA and MCSA Projects'/'mcsa project'"

abhay@jcmaxwell:~$ source .bash_profile
abhay@jcmaxwell:~$ $MCSA
bash: /home/abhay/Desktop/'GA: No such file or directory

Again, it doesn't work.

But the quotes and escape characters work when trying to access a folder directly! Look!

abhay@jcmaxwell:~/Desktop$ cd 'Dec 2011 Tasks'
abhay@jcmaxwell:~/Desktop/Dec 2011 Tasks$
abhay@jcmaxwell:~/Desktop/Dec 2011 Tasks$ cd ..
abhay@jcmaxwell:~/Desktop$ cd Dec\ 2011\ Tasks
abhay@jcmaxwell:~/Desktop/Dec 2011 Tasks$

What is wrong? What am I missing that is causing this to happen?

I am using Ubuntu 10.04.
Old 02-03-2012, 06:05 PM   #2
Registered: Feb 2009
Posts: 282

Rep: Reputation: 54
Try using single quotes.
export MCSA='$DESKTOP/GA and MCSA Projects/mcsa project'
Works for me.
Old 02-04-2012, 07:29 AM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,848

Rep: Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012
Use either quote-marks or backslashes, but not both, as they do the same thing.

The purpose of quoting and backslashing is to tell the shell to ignore characters that usually have reserved meanings, and to only parse their literal values.

Note that double-quotes do allow certain expansions to occur, one of which is backslash-escapes. But as the bash man page explains: "The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or <newline>." So a backslash followed by a space character will be treated literally, when enclosed in double-quotes.

Once a string is stored in a variable, all characters in it retain their literal values only, with the main exception being that unquoted variable strings are still subject to word splitting and glob expansion.

See here for more on how the shell parses whitespace and quotes:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to escape single quotes in sed for multi line pattern XXLRay Linux - Software 1 07-18-2011 08:35 AM
escape characters in Linux apeselis Programming 1 11-11-2010 05:16 PM
[SOLVED] double-quotes do not escape properly (bash=python) fabienhenon Programming 3 05-03-2010 04:23 PM
Ubuntu 8.04 loses my $PATH. Why do I have to repeatedly export PATH= ? oouc Ubuntu 10 09-14-2009 12:54 AM
escape characters not escaping BobNz Linux - Software 2 04-09-2004 04:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:19 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration