-1

Here is what I tried:

#! /bin/sh
    if [ -z "${ENCRYPT_ALL_PWD}" ]; then
        if [ ! -z $SA_USER ]; then
            DBAUSER=$SA_USER
            $ECHO "Yahoo!!!!!!!!!!!!"
         else
            $ECHO "Please define variable SA_USER in $HOME/<blah>profile and run this script again..."
            exit 1
         fi
    fi

But I am unable to get rid of the "not found" in the output when ENCRYPT_ALL_PWD is undefined:

$ sh -x swar_test.sh
+ [  != YES ]
+ [ ! -z ]
+ Please define variable SA_USER in <blah>/<blah>profile and run this script again...
swar_test.sh[7]: Please define variable SA_USER in <blah>/<blah>profile and run this script again...:  **not found**
+ exit 1

I have tried this as well, but it doesn't work either, and gives a "not found" when ENCRYPT_ALL_PWD is undefined/empty:

#! /bin/sh
if [ "${ENCRYPT_ALL_PWD}" != "YES" ]; then
    if [ ! -z $SA_USER ]; then
        DBAUSER=$SA_USER
        $ECHO "Yahoo!!!!!!!!!!!!"
     else
        $ECHO "Please define variable SA_USER in $HOME/<blah>profile and run this script again..."
        exit 1
     fi
fi
exit 0

What am I doing wrong here? How do I get rid of the "not found"?

My expectation is that when ENCRYPT_ALL_PWD is undefined/empty, and SA_USER is undefined as well, the output should be:

Please define variable SA_USER in $HOME/<blah>profile and run this script again...

closed as off-topic by Jeff Schaller May 9 at 14:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller
If this question can be reworded to fit the rules in the help center, please edit the question.

  • What is the value of $ECHO? My guess is it is undefined. – SethMMorton May 9 at 14:20
  • You are right. I was a total dunce not to see it before. There is an init file that sets ECHO: ECHO='/usr/bin/echo'. I had to import that. – Swarna Gowri May 9 at 14:30
  • or else use ${ECHO-echo} this way undefind ECHO will fall back to shell's default. – Archemar May 9 at 14:32
  • Thanks for the suggestion! – Swarna Gowri May 9 at 14:35
  • 1
    @Rui -- please do not edit questions that are on hold unless you think that the edits make the question good enough to reopen. Thank you! – Jeff Schaller May 12 at 20:49
1

This set it right:

$ cat swar_test.sh
    #! /bin/sh

    . $HOME/tools/init.sh
    . $HOME/<blah>profile
    if [ "${ENCRYPT_ALL_PWD}" != "YES" ]; then
        if [ ! -z $SA_USER ]; then
            DBAUSER=$SA_USER
            $ECHO "Yahoo!!!!!!!!!!!!"
         else
            $ECHO "Please define variable SA_USER in $HOME/aaaprofile and run this script again..."
            exit 1
         fi
    fi
    exit 0

Not the answer you're looking for? Browse other questions tagged or ask your own question.