Women in Technology

Hear us Roar



Article:
  Apache Web-Serving with Mac OS X: Part 2
Subject:   PATH Environment Variable from printenv
Date:   2002-04-03 20:48:46
From:   yaruki
When I run the "printenv" CGI script from the main site folder, the PATH environment variable looks like:
"/usr/bin:/bin:/Users/shortname", where shortname is my short login name on that box.
Questions:
1) How is this path getting set?
2) What is this PATH, exactly? Is it a path that CGI scripts search for other executables? It doesn't seem to have anything to do with the URL request itself.
3) It seems like that last entry shouldn't be there, should it? Why or why not?
Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Morbus Iff photo PATH Environment Variable from printenv
    2002-04-16 17:00:20  Morbus Iff | O'Reilly Author [View]

    The PATH can roughly be stated as "anytime I run a program, I'll look for it in my PATH". So say, for example, that you write a perl script that uses the "grep" command. Because your PATH is set to /usr/bin OR /bin OR /Users/morbus, you can simply say "grep [command line flags]" in your perl script.

    If, on the other hand, grep was not in either of those three directories, than you'd have to specify it's full path, like, for example: "/usr/local/sbin/grep [command line flags]". The PATH is set via environment variables - any time you log into the Terminal, a PATH is magically set. It allows you to say stuff like "perl myscript.pl" as opposed to "/usr/bin/perl/myscript..pl".

    As for the /Users/morbus showing up in the path, it's pretty normal. PATH's automatically are defined with common directories (like /usr/bin and /bin), but very often, they define the current user's home directory as part of the PATH as well. It's nothing you'd really be worried about (although, you CAN override the PATH in your perl scripts - this will affect the perl script only, not the generic PATH of your webserver).