-
Help with KSH
I am on HP 9000/785 11.11 HPUX system and getting errors when trying
to source a generated file by a third party product. The job of
this script is to setup more env variables. The user is running
under /bin/ksh. The jist of it is as follows:
#
#
#
if [ "$MWJ_ROOT" != "" ]; then
MWJ_ROOT=/tmp/mwj
fi
When this script is run and MWJ_ROOT is not set, I get the following
error:
$ . ./mwjsetup.sh
KSH: MWJ_ROOT: parameter not set
Why is this occurring here? It is ok in /bin/sh. And I even tried
putting the #!/bin/sh at the top of the file but it did not help
out. Is there a different way of checking for an empty variable in
KSH?
send replies to [email]mikejenkins1@hotmail.com[/email] or post to this group.
-
Re: Help with KSH
In article
<5fa2ceae-ff1a-4a1b-aefe-4ac18c8a2d25@f63g2000hsf.googlegroups.com>,
spastiman <mikejenkins1@hotmail.com> wrote:
[color=blue]
> I am on HP 9000/785 11.11 HPUX system and getting errors when trying
> to source a generated file by a third party product. The job of
> this script is to setup more env variables. The user is running
> under /bin/ksh. The jist of it is as follows:
>
> #
> #
> #
> if [ "$MWJ_ROOT" != "" ]; then
> MWJ_ROOT=/tmp/mwj
> fi
>
>
> When this script is run and MWJ_ROOT is not set, I get the following
> error:
>
> $ . ./mwjsetup.sh
> KSH: MWJ_ROOT: parameter not set
>
> Why is this occurring here? It is ok in /bin/sh. And I even tried
> putting the #!/bin/sh at the top of the file but it did not help
> out. Is there a different way of checking for an empty variable in
> KSH?[/color]
It sounds like you have "set -u" enabled, which causes references to
unset variables to cause an error rather than just an empty string.
A safe way to set a variable to a default value if it's not set is:
: ${MWJ_ROOT=/tmp/mwj}
":" is the shell's "do nothing" command, it just processes its
arguments. See the section of the ksh man page on Parameter Expansion
for an explanation of ${MWJ_ROOT=/tmp/mwj}.
--
Barry Margolin, [email]barmar@alum.mit.edu[/email]
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
-
Re: Help with KSH
2008-04-16, 05:45(-07), spastiman:[color=blue]
> I am on HP 9000/785 11.11 HPUX system and getting errors when trying
> to source a generated file by a third party product. The job of
> this script is to setup more env variables. The user is running
> under /bin/ksh. The jist of it is as follows:
>
> #
> #
> #
> if [ "$MWJ_ROOT" != "" ]; then
> MWJ_ROOT=/tmp/mwj
> fi
>
>
> When this script is run and MWJ_ROOT is not set, I get the following
> error:
>
> $ . ./mwjsetup.sh
> KSH: MWJ_ROOT: parameter not set
>
> Why is this occurring here? It is ok in /bin/sh. And I even tried
> putting the #!/bin/sh at the top of the file but it did not help
> out. Is there a different way of checking for an empty variable in
> KSH?[/color]
[...]
There must be a:
set -u
somewhere in your startup script, which is not such a wise thing
to do.
A more usual way to test if a string is non-empty is:
if [ -n "$MWJ_ROOT" ]; then
to overcome "set -u":
if [ -n "${MWJ_ROOT:+set-and-non-empty}" ]; then
You can also do:
MWJ_ROOT=${MWJ_ROOT:+/tmp/mwj}
Though that will set MWJ_ROOT to an empty string if it was
previously unset.
--
Stéphane
-
Re: Help with KSH
yes the 'set -u' was the culprit and was setup in the /etc/d.profile
file.
I have commented it out and stated why. Thanks for the help.
-------
Michael