techy1
July 18, 2014, 11:06pm
1
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.
output is "none"
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
techy1
July 19, 2014, 5:23am
3
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.
The XSI extensions specifying the -a and -o binary primaries and the '(' and ')' operators have been marked obsolescent. (Many expressions using them are ambiguously defined by the grammar depending on the specific expressions being evaluated.) Scripts using these expressions should be converted to the forms given below. Even though many implementations will continue to support these obsolescent forms, scripts should be extremely careful when dealing with user-supplied input that could be confused with these and other primaries and operators. Unless the application developer knows all the cases that produce input to the script .....
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.
techy1
July 19, 2014, 7:16am
8
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..
Q15. Does removal of obsolescent utility syntax mean that implementations supporting usages of head -5 file, tail -5 file, tail -l file are no longer allowed?
No, in general the intent of removing the obsolescent forms of the utility synopses was not to disallow them to be supported by implementations but to downgrade the status of their use in applications from conforming application using an obsolescent feature to non-conforming application. In general it is allowed for utilities to have extensions that violate the utility syntax guidelines so long as the forms defined in the standard that are required to follow the utility syntax guidelines do so. The cases cited fit the case. The Austin Group has more general cases under review at the present time.
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..
techy1
July 19, 2014, 7:48am
10
scrutinizer:
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?