Operating System - HP-UX
1826663 Members
2817 Online
109695 Solutions
New Discussion

Having problem with ksh, environment variable not set

 
Ajay Sishodia
Frequent Advisor

Having problem with ksh, environment variable not set

Hi all,
I am trying to set some environment variable. This variables are define in a file as export VBHOME=VHOME/xyz. When I source this file, I get VHOME not set, but if I change the shell to sh, I don't get this issue. Please help

Thanks
Sushil Singh
6 REPLIES 6
Charles Slivkoff
Respected Contributor

Re: Having problem with ksh, environment variable not set

I believe you may have meant:

export VBHOME=$VHOME/xyz

right?

If so, try adding a "set +u" (the opposite of "set -u") to the script before you try to dereference VHOME. ksh is likely treating unset variables as errors.

$ echo $ASDF

$ set -u
$ echo $ASDF
ksh: ASDF: parameter not set
$ set +u
$ echo $ASDF


You can use $- to determine if "u" is set or unset:

$ echo $-
ism
$ set -u
$ echo $-
isum

Dave La Mar
Honored Contributor

Re: Having problem with ksh, environment variable not set

Sushil -
We often find it less cluttering to export the variables directly in the script so as not to source in more than is needed.
Not the answer for your why, but a solution for your problem none the less.

Best of luck.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
hein coulier
Frequent Advisor

Re: Having problem with ksh, environment variable not set

look at het man page of ksh :
you can use ${parameter:-word}

export VBHOME=${VHOME:-""}/xyz
Mark Grant
Honored Contributor

Re: Having problem with ksh, environment variable not set

So what shell are you using to start with?

How are you sourcing this file because I can't think of any circumstances where "export VBHOME=VHOME/xyz" will produce an error. Even if this a typo and it should read $VHOME it still shouldn't produce an error.
Never preceed any demonstration with anything more predictive than "watch this"
Ajay Sishodia
Frequent Advisor

Re: Having problem with ksh, environment variable not set

Sushil,

How you are posting questions using my ID???????? I don't think I know you. Did you hack into my account on ITRC?

Ajay
David Andrews_1
Advisor

Re: Having problem with ksh, environment variable not set

If you want to set a default location in the event that VHOME is not set type:

VBHOME=${VHOME:-/usr/local}/xyz

If $VHOME is not set then VBHOME will be set to:

/usr/local/xyz