[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: condition to execute

From: Greg Wooledge
Subject: Re: condition to execute
Date: Tue, 6 Jul 2021 07:10:20 -0400

On Tue, Jul 06, 2021 at 05:52:28AM +0200, wrote:
> Demo:
> $ f=0; (( f == 1 )); echo $?
> 1
> $ f=1; (( f == 1 )); echo $?
> 0
> The exit status.  Do people always ensure exit status is correct?
> When `f` is not `1`, I just print some help.

There are a couple reasons this was brought up.

First, sometimes people write shell scripts that use set -e, no matter
how hard we tell them not to.  In such scripts, the author is
constantly dancing around land mines.  Every simple command must be
guaranteed to exit 0 or else the script crashes.  It's the most idiotic
way you can possibly write a shell script, but people do it *constantly*.

So, in that kind of environment, the difference between A && B and
if A; then B; fi is quite significant.

Second, some people tailor their interactive shell to react in a special
way when one of their commands exits with a nonzero status.  Maybe they
change the color of some piece of their prompt, or add punctuation
characters to the prompt to draw attention, or something like that.

Having an innocuous command return nonzero might be bothersome in
that environment.

There may be other reasons, but those are the big two I can think of.
It's just something to be aware of.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]