Using sed and if multiple conditions

Hi

I've been trying to get this to work but so far no luck.

    #!/usr/bin/ksh

unset EXP
APP=$1
EXP=`sed -n "/${APP}/p" tIclrpt.out |awk '{print $7}'|sed '/^$/d'`
EXT=`sed -n "/${i}/p" ${SESLOG} |awk '{print $4}'|grep "${i}"`
EXEM=/path/to/fail
ACTI=/path/to/success

if [ -z $EXP ] || [ -z $EXP = none ]
then
echo " this has a value"
echo " EXP Value is: ${EXP} "
echo "${APP}" >> $ACTI
else
echo "${APP}" >> $EXEM
fi

I need 1 of the two conditions met to log the application into a log that can be used to recycle the application at a later time.

Sometimes when you query this app, it will display one of two characters with that sed i used.

  1. output is "none"
  2. output is blank

In a test, just to echo if it's working or not, it always see's the blank line as a value.
if I do it this way with the application of value = none

if [ -z $EXP ] || [ -z $EXP = none ]

It works the way it should.

But if the value is blank i get this:

exp3.ksh[6]: test: argument expected
 this has a value
 EXP Value is:
if [ -z "$EXP" ] || [ "$EXP" = "none" ]
then
1 Like

hey thanks! actually figured it out when i took a break lol... over thinking it too much. It was actually supposed to be:

if [ -z "$EXP" -o "$EXP" = "none" ]

Note: -o works too, but it has been marked obsolescent, and therefore MadeInGermany's suggestion is the preferred approach.

See Test: Application Usage

Really? I think -o within [ ] (test) is quite okay. Perhaps you mean the [[ ]] compound that has || for "or".

No I mean the standard test.

Test: Application Usage

1 Like

Interesting - this would break thousands of old scripts.
In old times test and even [ were an external command; -a and -o were most efficient.

IMHO they should leave it alone and recommend the [[ ]] instead.

Strange. If i dont use the -o it just doesnt work. Its been a really long time since i had to use -o i forgot about that option

Why would that break old scripts ? -a and -o will most likely remain supported by the implementations ...

Obsolescent means that is has become outdated and its usage is discouraged, for the reasons given and there is the intention to remove it from the standard..

POSIX.1 FAQ

---

What version of ksh are you using on what OS? Even though older implementations are not POSIX compliant, they should support that syntax..

I don't understand it myself. I just ran it on my Linux system at home and works fine.

The one I need it for is using AIX.

ksh version Version M-11/16/88f
I just looked up the version as well:

88f   
 Version M-11/16/88f-beta4     IRIX 5.3-6.3    
 Version 11/16/88f   IRIX 6.3+   
 
 Version M-11/16/88f  OSF1/V4+ 
 AIX 4.3.*, AIX 5.1-3 
 IRIX-6.5.5 
 HP-UX 10,11 /usr/bin/sh   


In the HP-UX 11 /bin/sh the undocumented flag "Q" disables reading of $ENV at startup.   

I just tried it with Version M-11/16/88f on AIX and it works fine..

$ [ -z "$EXP" ] || [ "$EXP" = "none" ] && echo hllo
hllo
$ EXP=
$ [ -z "$EXP" ] || [ "$EXP" = "none" ] && echo hllo
hllo
$ EXP=none 
$ [ -z "$EXP" ] || [ "$EXP" = "none" ] && echo hllo
hllo
$ EXP=foo
$ [ -z "$EXP" ] || [ "$EXP" = "none" ] && echo hllo     
$ 

Can you post the result that you get?