How to expand paths in $PATH like "~/bin" to full path?

How to expand paths in $PATH like "~/bin" to full path?

Post by Steven Bro » Mon, 20 Oct 1997 04:00:00



I need to read the PATH environment variable and make use of it in a program
I'm writing, the problem is, the PATH contains ~ references which the kernel
doesn't like one bit.  Is there a function I can call to expand the path?
If not, how do I get the home directory of a user?  Thanks!

 
 
 

How to expand paths in $PATH like "~/bin" to full path?

Post by Guy Mao » Tue, 21 Oct 1997 04:00:00



> I need to read the PATH environment variable and make use of it in a program
> I'm writing, the problem is, the PATH contains ~ references which the kernel
> doesn't like one bit.  Is there a function I can call to expand the path?
> If not, how do I get the home directory of a user?  Thanks!

Tilde expansion functions are included in libreadline.  See
/usr/include/readline/tilde.h.

Guy

 
 
 

How to expand paths in $PATH like "~/bin" to full path?

Post by Rob Rya » Tue, 21 Oct 1997 04:00:00


There shouldn't *BE* unexpanded ~s in PATH.  That's a misuse of PATH
(and or ~).  ~ expansion is a function of the shell.  If using a csh
variant use:

set path=(~/foo etc...)

if using an sh variant

PATH=$HOME/foo:etc...

If you have other ~ refs you'll have to expand them manually.

-Rob

 
 
 

1. set path = "$path" hoses path in tcsh -- why???

All:

  % echo $path
  /usr/local/bin /usr/pubsw/bin /usr/bin ...
  % ls
  [... etc ... it works]
  % set path = "$path"   *** What the hell happens here??? ***
  % echo $path
  /usr/local/bin /usr/pubsw/bin /usr/bin ... looks the same
  % ls
  ls: Command not found.

This is just a particularly egregious illustration of the problem. In
general, if I try to do something like this:

  % set savedPath = "$path"  # Save current path
  % set path = "$savedPath"  # Restore saved path

it doesn't work. The path *looks* the same, but the shell can't find
anything. Recall that the shell variable path and the environment
variable PATH are linked, so setting one automatically sets the other
also. Some unexpected feature of list interpolation perhaps? Bug or
feature, I call it a pain...

Andrew Duncan

2. Ancient Compaq Onboard NIC

3. should argv[0] = "/full/path/to/pgm" or "pgm"?

4. mounting remote drives w/ samba - how?

5. .cshrc path problem: "ridiculously long path truncated!"

6. X-Windows in VGA mode

7. PATH set by "rsh localhost echo \$PATH"

8. Quantum Ontrack Driver and LILO

9. Secure CGI Path Access (translate file path "/" to user homedir)

10. Path as "su" doesn't equal path as root or as login user

11. add in the PATH a path if not present in the PATH

12. ksh: add path to $PATH only when ot yet in $PATH

13. zsh's 'typeset -U path' wipes out path/PATH