1832240 Members
2546 Online
110041 Solutions
New Discussion

PATH Variable Length

 
SOLVED
Go to solution
Walter Bezdek
Occasional Advisor

PATH Variable Length

Hello fellow admins

One of my clients asked me a question that I have not been able to find an answer to.

Is there a limit on the lenght that the PATH environment variable can be in HP-UX 10.20?

Thanks.

Tony
7 REPLIES 7
Mark Greene_1
Honored Contributor

Re: PATH Variable Length

It depends on the shell you are using, and the OS and hardware. The c-shell is the only one with true limits: max of 18 characters for a variable name, and 500-something characters in the contents. The other shells, AFAIK, are limited only by the kernel parameters, which of course are a function of the hardware--chiefly 32 vs 64 bit architecture. So if you are not careful (and are really sloppy), you can consume your memory and/or swap with a script that uses variables with large contents.

HTH
mark
the future will be a lot like now, only later
harry d brown jr
Honored Contributor

Re: PATH Variable Length

I just tested both 10.20 and 11.x and I got up to 64K before I quit - boring.

PATH=$PATH:$PATH
echo $PATH|wc

Of course the big QUESTION is why would anyone care? If you have that many "BIN" directories, then you need to rethink your application interface.


live free or die
harry
Live Free or Die
A. Clay Stephenson
Acclaimed Contributor

Re: PATH Variable Length

Hi:

In 10.20 there is no inherent limit to PATH as such BUT there is a limit to the total size of the environment variables (of which PATH is but one) and the command line args passed to the exec() system call. Since processes fork() and exec() this becomes the effective limit.

This can be changed by building a new kernel but the total space is fould in a define NCARGS in /usr/include/sys/param.h. The default value is 20480.
If it ain't broke, I can fix that.
Wodisch
Honored Contributor

Re: PATH Variable Length

Hello,

basically not, if you set it from within a program. But there is a limit to the length of a command line, which restricts the length of your PATH, in case you try to set from command line...

HTH,
Wodisch
Walter Bezdek
Occasional Advisor

Re: PATH Variable Length

The answers were mixed, so I put a call in with HP. I received the following response from HP:

I checked the max length for the path variable and it is 1024 characters, so we
should be okay there. What error message gets reported back when it fails to
find the executable? What happens if you move the path to beginning of your
path variable? For example. at your command prompt type:

export PATH=/home/joe:$PATH

Note: Replace the "/home/joe" with the path name to the executable you want to
run.

Thanks to Joseph Tarr at HP for the answer.
Peter Kloetgen
Esteemed Contributor

Re: PATH Variable Length

Hi Anthony,

if you execute a command and the shell tries to find the executable, she reads the PATH-variable from the beginning to the end and looks in each specified directory and seeks the command in it. If the executable is not found, the next directory is checked. If all specified directories are checked, and the command is still not found, the error message:

sh: command_you_wanted_to_execute: not found

is given. If your PATH-variable is too long, the too_much_directories won't be read and the same error should occur. If you put the directory to the beginning of PATH like descripted, the directory will be checked and the command will be found and executed.

Please remember, when editing the /etc/PATH- file, it has to be only one line, so begin adding directories with "A" out of command mode.


Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Mark Greene_1
Honored Contributor
Solution

Re: PATH Variable Length

The first 4 replies you got all answered your question, just not the way you wanted.

To recap: The limit is shell and hardware and OS dependant the only shell with an explicit limit is the C-shell, 512 characters on the PATH variable. All the other shells are limited by the kernel parameters, which are a function of the system being 32 or 64 bit.

The 1024 limit you were told is simply the command line limit, as Wodisch mentioned. You can exceed this in a script, as Harry demonstrated. Simply setup a script with two 1024 character long directory paths into variables, and then do:

PATH=$VAR1:$VAR2

and now you have a path variable that is 2048 characters long.

So maybe call the HP tech back and ask him to test it in a script versus just typing it at the command line.

HTH
mark
the future will be a lot like now, only later