Old ksh doesn't have '!=="not"' -- What to do?

Old ksh doesn't have '!=="not"' -- What to do?

Post by Paul Kirka » Fri, 13 Jun 1997 04:00:00



Hi.

I have several ksh scripts with lines like:

if ! TestCommand ; then
        blah,blah
fi

which doesn't work on some older systems.  Is
there any general way to re-produce the negation
effect of the bang?  I of course could do:

if TestCommand ; then
   echo "Going to next step"
else
   blah, blah
fi

but that's too ugly.

Any tips appreciated.

Paul

--
Paul Kirkaas

 
 
 

Old ksh doesn't have '!=="not"' -- What to do?

Post by Kent Squire » Fri, 13 Jun 1997 04:00:00



> Hi.

> I have several ksh scripts with lines like:

> if ! TestCommand ; then
>         blah,blah
> fi

> which doesn't work on some older systems.  Is
> there any general way to re-produce the negation
> effect of the bang?  I of course could do:

> if TestCommand ; then
>    echo "Going to next step"
> else
>    blah, blah
> fi

> but that's too ugly.

> Any tips appreciated.

> Paul

> --
> Paul Kirkaas


update ksh

 
 
 

Old ksh doesn't have '!=="not"' -- What to do?

Post by Marc Olzhe » Fri, 13 Jun 1997 04:00:00


Hi.

[snip]
:which doesn't work on some older systems.  Is
:there any general way to re-produce the negation
:effect of the bang?  I of course could do:
:
:if TestCommand ; then
:   echo "Going to next step"
:else
:   blah, blah
:fi
:
:but that's too ugly.
:
:Any tips appreciated.

You can use the || and && construction:

if foo; then
        bar1            ==      foo && ( bar1; bar2; ... )
        bar2
        ...
fi

if ! foo; then
then
        bar1            ==      foo || ( bar1; bar2; ... )
        bar2
        ...
fi
:
:Paul
Marc

 
 
 

Old ksh doesn't have '!=="not"' -- What to do?

Post by Donn Ca » Fri, 13 Jun 1997 04:00:00


...
| You can use the || and && construction:
...
| if ! foo; then
| then
|       bar1            ==      foo || ( bar1; bar2; ... )
|       bar2
|       ...
| fi

Pretty close, but the parentheses will cause the shell to fork a
subprocess, which is not only unnecessarily expensive but also changes
the semantics with respect to variables inside the block.

Use { } to get the block without the subprocess.  Don't forget to white-space
separate them and include a line terminator at the end - { echo like this; }
{echo not like this}.  Because stuff like that makes me cranky, I prefer

if foo
then :
else
        bar1
        ..
fi

And of course, if you have strings to compare, use "case", that's what
it's for.

        Donn Cave, University Computing Services, University of Washington

-------
Today's Fun Spelling Tip:

   It's vs. its ... ever wonder whether you're getting it right?
   Try he's vs. his, which follows the exact same rules.

 
 
 

Old ksh doesn't have '!=="not"' -- What to do?

Post by Paul Kirka » Sat, 14 Jun 1997 04:00:00




>> 'if ! TestCommand' ... doesn't work on older ksh...
>> Any tips appreciated.
>update ksh

Uh, duh, *MY* ksh works fine; I want to make my script portable to
others with older versions.  It's not really necessary to waste
tiem and bandwidth with pointless quips.

Paul

--
Paul Kirkaas

 
 
 

1. Why doesn't echo "text" 'command' "more text" work?

                 ^                                        ^
Wrong quotes, should be -
   echo "You have" `grep Subject: /usr/spool/mail/me | wc -l` "messages."
or -
   echo "You have `grep Subject: /usr/spool/mail/me | wc -l` messages."

But, another problem is, if you've no mail, /usr/spool/mail/me does not
exist, leading grep to say:
   grep: can't open /usr/spool/mail/me
Wc will still report 0.

You might try -
   sh -c 'echo "You have `grep 2>/dev/null Subject: /usr/spool/mail/me | wc -l` messages."'

Hope this helps.

2. HOWTO: NIS-based authentication with Apache-1.3.1?

3. Term and AIX

4. awk '{gsub("old","\n"); print}' adds additional new line

5. RFD: comp.os.linux.security

6. It Doesn't Matter (much) If Sun Doesn't "Support" Dataless

7. LAN Party Server running RedHat 6.1 Setup Problems ! Please Help!

8. can't compile gnome - "'gtk-config' script not found"

9. X won't start "could not find font 'fixed'"

10. sendmail and it's message: "database '@' has not been defined"

11. Why Unix people write `...' and not '...' or "..."?

12. Does FreeBSD 3.0' ksh support "print" and "function" ?