Operating System - HP-UX
1828390 Members
2716 Online
109977 Solutions
New Discussion

ksh error "parameter not set"

 
SOLVED
Go to solution
eric stewart
Frequent Advisor

ksh error "parameter not set"

I have this script extract.
I want to run it in the current shell.
How do I get past the error message as shown below. I have included the script and the output.
TIA
>cat tmap
if [ "${PROTOCOL_name}" = "" ]
then
echo enter protocol name
read PROTOCOL_name
fi

>. tmap

ksh: PROTOCOL_name: parameter not set
>
Good help is easy to find within forums
7 REPLIES 7
Stefan Farrelly
Honored Contributor

Re: ksh error "parameter not set"


That is a very good question. Tried running it myself, works fine. Cant recreate your error no matter what I do. Try this command and let us know the output;

/sbin/sh -x ./tmap
Im from Palmerston North, New Zealand, but somehow ended up in London...
John Palmer
Honored Contributor
Solution

Re: ksh error "parameter not set"

Include the line

set +u

at the beginning of your script to prevent it from complaining about the use of undeclared variables.

Or you could simply assign a value to PROTOCOL before using it.
PROTOCOL=""

The latter is better programming practise as having the shell fail if you use an undeclared variable is useful for picking up typos in your script.
John Palmer
Honored Contributor

Re: ksh error "parameter not set"

Stefan,

You couldn't recreate it because your shell was already ignoring undeclared variables.

Set -u is normally called in the user's .profile script.

Regards,
John
Vikas Khator
Honored Contributor

Re: ksh error "parameter not set"

Hi,

If you have
set -u for the ksh then you will get the exact error.

Try adding a set +u
before you check for the if condition.

For more info do a man on ksh and look for all set options.

Hope it helps.
Vikas
Keep it simple
Dhr. Ron van Eijk
New Member

Re: ksh error "parameter not set"

Although I cannot completely explain why it works, this is the (a) solution:

Add the following line as the first one in your script:

#!/usr/bin/sh

When you execute this script, the variable will be set, and the script does not ask for input, until you delete the variable with 'unset'.

Gert Leerdam
eric stewart
Frequent Advisor

Re: ksh error "parameter not set"

Thanks,
I needed to know if the script had been executed before within the same session so I could do some housekeeping items. I just did not want the user to get the error message.
Thanks again.
Good help is easy to find within forums
John Palmer
Honored Contributor

Re: ksh error "parameter not set"

Eric,

Maybe your best bet for that is to export readonly variable the first time that you run it. This will be available to any subsequent shell and cannot be unset or changed.

readonly FLAG="set"
export FLAG

Regards,
John