1753770 Members
4926 Online
108799 Solutions
New Discussion юеВ

PATH variable and batch

 
Ian Warner
Trusted Contributor

PATH variable and batch

On HP-UX 11i -

If i type PATH=opt/wotever:$PATH, the path changes. I can confirm this using echo $PATH.
If i execute a batch file, usingg the same command, it does not work, the PATH remains the same.
What am I missing???????????

TIA Ian
Why did anyone invent unix?
4 REPLIES 4
Arunvijai_4
Honored Contributor

Re: PATH variable and batch

Hi Ian,

I think, you have export with full path not relative. When you execute a script or batch file, it spawns a shell and export PATH to that particular child shell, when it finishes execution, PATH will be no longer available to parent.

Hope this is clear.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
A. Clay Stephenson
Acclaimed Contributor

Re: PATH variable and batch

It looks like you failed to export the variable

PATH=/opt/wotever:${PATH}
export PATH

or combine in 1 statement:
export PATH=/opt/wotever:${PATH}

I assume the missing leading "/" before "opt" was a typo.
If it ain't broke, I can fix that.
Ian Warner
Trusted Contributor

Re: PATH variable and batch

A search found the answer in an earlier question.

Ta.
Why did anyone invent unix?
A. Clay Stephenson
Acclaimed Contributor

Re: PATH variable and batch

Oh, you may be failing UNIX 101. If you set PATH in a child process then the child's environment can never be inherited by the parent.

I'll assume that you are setting PATH in something like myvars.sh

echo "Before: ${PATH}"
myvars.sh
echo "After : ${PATH}" # these will be the same

The "trick" is to source your script via the "dot" operator so that it becomes a part of the current process.
echo "Before: ${PATH}"
. myvars.sh
echo "After : ${PATH}" # these will different

When myvars.sh is sourced it must not contain an exit or return statement because now you will exit the foreground process.
If it ain't broke, I can fix that.