Help with KSH - Unix

This is a discussion on Help with KSH - Unix ; 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. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Help with KSH

  1. 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 mikejenkins1@hotmail.com or post to this group.

  2. Re: Help with KSH

    In article
    <5fa2ceae-ff1a-4a1b-aefe-4ac18c8a2d25@f63g2000hsf.googlegroups.com>,
    spastiman wrote:

    > 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?


    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, barmar@alum.mit.edu
    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 ***

  3. Re: Help with KSH

    2008-04-16, 05:45(-07), spastiman:
    > 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?

    [...]

    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

  4. 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

+ Reply to Thread