Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.