Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Red Hat Enterprise 5.3, and I'm trying to add a directory to my $path variable, but it has spaces in it. The $path variable is space delimited, so how do I differentiate a space in a absolute path from a space that separates the paths?

share|improve this question
    
glad this got tagged "tcsh" but you should mention explicitly in the body (or headline or both) the shell that you're using – quack quixote Oct 7 '09 at 23:19
    
Agreed. I'm the one who added the tcsh tag, but that was my speculation. Brad -- did I guess right? – Doug Harris Oct 8 '09 at 1:45

Isn't $PATH colon-delimited? Anyway, you need to escape the spaces with \. If you wanted to have a directory called my dir, you'd do something like this:

PATH=/bin /usr/bin /home/user/my\ dir /sbin

This path is just an example, don't copy it verbatim.

share|improve this answer

It looks like Brad is using csh or tcsh -- these shells have both $path and $PATH. The shell maintains both when you change the one.

The way to add the directory with spaces to $path:

% echo $path
/opt/local/bin /opt/local/sbin /usr/local/bin /usr/local/sbin /Users/dharris/bin
% echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/Users/dharris/bin

% set path = ($path /tmp/directory\ with\ spaces)

% echo $path
/opt/local/bin /opt/local/sbin /usr/local/bin /usr/local/sbin /Users/dharris/bin /tmp/directory with spaces
% echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/Users/dharris/bin:/tmp/directory with spaces
share|improve this answer
    
$path works as you show it, but when I echo $PATH there is a : instead of a space in each space of the path. – Brad Oct 7 '09 at 22:18
    
Which shell are you using? – Doug Harris Oct 8 '09 at 1:45

In my case (using csh) the $PATH variable was messing it up and preventing $path from working, so here is a workaround:

set savePATH = $PATH
set path = ($path /usr/my\ dir/has\ spaces\ in\ it)
set PATH = ($savePATH)

Caveat: paths with spaces must be added last, if you add a non-space path to path after this, it will automatically update $PATH and break it again.

share|improve this answer
    
but now you've left the dir-with-spaces off the $PATH; you should "set savePATH = ($PATH:/usr/my\ dir/has\ spaces\ in\ it)". – quack quixote Oct 7 '09 at 23:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .