Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 looking for a way to easier manage my $PATH variables.

executing $PATH returns me:

/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin: No such file or directory

To me this is total crap and hard to read.

Can they be listed like so:

/usr/X11/bin: No such file or directory

I'd love to manage my $PATH using Ruby but naturally it looks like I needs to stay as part of my shell configuration files.

share|improve this question
If you are just looking to display it nicer you could use a command like this. echo $PATH | sed -e 's/:/\n/g' – Zoredache Feb 8 '10 at 17:58
Can I put them into my profile on separate lines? – JP Silvashy Feb 8 '10 at 18:32
Another display incantation: printenv PATH | tr ":" "\n". For manipulating it in scripts see (on Stack Overflow)… – dmckee Feb 9 '10 at 23:57
up vote 1 down vote accepted

You can list your pathspec out on multiple lines like so:


You may also append stuff to your path by doing


so you could have


At the risk of sounding like a crotchety old *NIX admin, please don't do strange and funky things like writing a ruby script to manage PATH for you -- You aren't going to be editing this very often (if you are you're probably doing something wrong), and you will be better served in this case by conforming to the same standards as everyone else, especially if/when you need to ask someone for help.

The colon-delimited path list isn't so terrible in the grand scheme of badly formatted things you'll find in the world :-)

share|improve this answer
echo $PATH | sed 's/:/:\n'

You can do something along the lines of:

PATH=$(ruby_prog $PATH)

in a startup script (or other script that is sourced) or at the shell prompt.

share|improve this answer

$PATH needs to look the way it does, though you can probably split it across lines using a backslash (untested, don't have a *nix or Linux machine available).

Why don't you write a Ruby script to parse it for you, and make it readable, and allow you to edit it? That'll be a nice little project.

share|improve this answer

If your server has Perl, and you don't mind using it, then you might try this one-liner to display your PATH (not manage it):

printenv PATH | perl -nl -0x3A -e 'print ++$i, " ", $_;'

I wrote the details about this on my tech BLOG.

share|improve this answer

On most servers we have both 64-bit and 32-bit application environments.

Everything 32-bit is compiled into /opt/32, everything 64-bit into /opt/64.

We then have a "set_env" script in both folders which sets the relevant PATH and LD_LIBRARY_PATH variables. If we want to run something 32-bit, we type

. /opt/32/set_env

or 64-bit:

. /opt/64/set_env

The format is, as voretaq7 suggested, laid out like so:

export PATH="\

(replace 32 with 64 in the 64-bit script.)

Just don't do what I did originally and indent the lines, because then it becomes " /opt/32..." - note the spaces, which then isn't a valid filesystem path!

share|improve this answer

Your Answer


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.