[Top][All Lists]

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

Re: Feature request

From: Dale R. Worley
Subject: Re: Feature request
Date: Sun, 08 Nov 2020 20:37:24 -0500

<vq@larryv.me> writes:
>> On Nov 8, 2020, at 6:49 PM, Budi <budikusasi@gmail.com> wrote:
>> Need feature on while's readily flag
>> $ i=;while ((i<5)) ;do let i++ ;echo $i ;done ;echo $?
>> 1
>> 2
>> 3
>> 4
>> 5
>> 0
>> $ i=7;while ((i<5)) ;do let i++ ;echo $i ;done ;echo $?
>> 0
>> we need feature on while's ability to supply flag when it's up to the
>> end of loop block
> It's not clear what you're asking for. Do you want while to exit
> nonzero when it doesn't perform any loops?

I suspect what Budi wants is more explicit control of the exit value of
the while block.  Of course, as long as the block is executed at least
once, it is straightforward to control the exit value.  Compare these
two examples:

$ i=0;while ((i<5)) ;do let i++ ;echo $i; true ;done ;echo $?

$ i=0;while ((i<5)) ;do let i++ ;echo $i; false ;done ;echo $?

What cannot be controlled is the exit value if the block is not executed
i.e. if the initial evaluation of the condition is false.  In that case,
the exit value is always zero.


reply via email to

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