I had something weird happen on my computer.
I had gperf installed under /usr/local/bin.
As related to questionI asked here I had a perl script running on my computer which contain the line system() on gperf with flags something look like
perl file:
system("gperf ...") == 0 || die "calling gperf failed: $?";
However no matter how hard I try the gperf will not run and out put the failed message
to debug I tried something like
system("echo \$PATH") == 0 || die "calling gperf failed: $?";
and found that it does not contain /usr/local/bin/ where i installed my gperf but only look in usr/bin where it was not installed
So the $PATH is wrong…
So I googled around and saw system() is same as calling /bin/sh inside a file so i tried /bin/sh and echo $PATH which found that it contain /usr/local/bin/ to my disbelieve.
So my question is where is the $PATH for a system() declared? why is it different then the one inside a Bourne shell ?
The
PATHused by commands launched viasystemis the same as the one in the perl script, accessible through$ENV{PATH}. It’s thePATHthat the perl script inherits from the program that called it, unless you changed it in the script.What’s biting you is probably that you set up your
PATHin the wrong configuration file. Define it in~/.profile,/etc/profileor other system-wide file, not in a shell configuration file such as.bashrc. See this question for some general information.If you want to set the path manually inside the perl script, you can use something like
but this is probably a bad idea: in most cases, your script should not modify the path chosen by the user who runs that script.
If you’re having trouble finding the right place to set
PATHon your system after reading the question I linked to and the questions linked in my answer there, ask on Unix & Linux and be sure to state the details of your operating system (distribution, version, etc.) and how you log in (this is a user question, not a programming question).