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/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
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.
You can do something along the lines of:
in a startup script (or other script that is sourced) or at the shell prompt.
$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.
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 :-)
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):
I wrote the details about this on my tech BLOG.
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
or 64-bit:
The format is, as voretaq7 suggested, laid out like so:
(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!