help-bash
[Top][All Lists]
Advanced

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

Re: Help-bash Digest, Vol 141, Issue 8


From: Budi
Subject: Re: Help-bash Digest, Vol 141, Issue 8
Date: Thu, 13 Jul 2023 08:14:39 +0700

@Greg Wooledge

Exactly absolutely correct !

Thanks

On 7/12/23, help-bash-request@gnu.org <help-bash-request@gnu.org> wrote:
> Send Help-bash mailing list submissions to
>       help-bash@gnu.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>       https://lists.gnu.org/mailman/listinfo/help-bash
> or, via email, send a message with subject or body 'help' to
>       help-bash-request@gnu.org
>
> You can reach the person managing the list at
>       help-bash-owner@gnu.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Help-bash digest..."
>
>
> Today's Topics:
>
>    1. Re: How do we get state of a flag in set -o ... (Chet Ramey)
>    2. Re: How do we get state of a flag in set -o ... (Chet Ramey)
>    3. Have a equivalent performing of goto (Budi)
>    4. Re: Have a equivalent performing of goto (Greg Wooledge)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 12 Jul 2023 09:45:05 -0400
> From: Chet Ramey <chet.ramey@case.edu>
> To: alex xmb ratchev <fxmbsw7@gmail.com>, help-bash
>       <help-bash@gnu.org>
> Cc: chet.ramey@case.edu
> Subject: Re: How do we get state of a flag in set -o ...
> Message-ID: <3686eaae-09ec-7dfe-15d4-b5d6b816e765@case.edu>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> On 7/11/23 5:15 PM, alex xmb ratchev wrote:
>> On Tue, Jul 11, 2023, 22:05 Greg Wooledge <greg@wooledge.org> wrote:
>>
>>> On Wed, Jul 12, 2023 at 02:54:10AM +0700, Budi wrote:
>>>> How do we get state of a flag in set -o ... that has no directly alias
>>>> set [-+] , e.g.
>>>> set -o posix
>>>> or
>>>> set -o vi
>>>> ?
>>>>
>>>> not, e.g. set -o errexit , as it can be retrieved by echo $-
>>>
>>> Parse the output of "set -o".
>>>
>>
>> i was trying some simple code but fatally failed
>
> This is a bad approach.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>
>
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 12 Jul 2023 10:19:23 -0400
> From: Chet Ramey <chet.ramey@case.edu>
> To: Kerin Millar <kfm@plushkava.net>, alex xmb ratchev
>       <fxmbsw7@gmail.com>
> Cc: chet.ramey@case.edu, help-bash <help-bash@gnu.org>
> Subject: Re: How do we get state of a flag in set -o ...
> Message-ID: <351efee9-be63-52ec-0c9a-ed573d152190@case.edu>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> On 7/11/23 6:11 PM, Kerin Millar wrote:
>
>> It is even true of variable expansion.
>>
>> $ declare -A map; str="two words"; map=( $str ); declare -p map
>> declare -A map=(["two words"]="" )
>>
>> It seems like a bug to me. It's certainly counter-intuitive. For indexed
>> arrays, word splitting occurs. I see no particular reason for associative
>> arrays to be a special case.
>
> You have it backwards. Word splitting doesn't happen on the rhs of an
> assignment statement. It happens for indexed arrays in this particular
> case because I did it for ksh compatibility (because the behavior of a list
> of words in a compound assignment to an indexed array was well-defined), so
> indexed arrays are the exception. Note that it doesn't take place for
> assignment words in a compound array assignment, making it even more of a
> special case.
>
> Now that key-value pairs in compound assignments to associative arrays
> are well-defined, it might make sense to extend the associative array
> compound assignments to perform word splitting, but that's not backwards
> compatible, and the whole idea of key-value assignments is to mimic
> the semantics of ( [key]=value ... ).
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>
>
>
>
> ------------------------------
>
> Message: 3
> Date: Wed, 12 Jul 2023 22:07:34 +0700
> From: Budi <budikusasi@gmail.com>
> To: help-bash@gnu.org
> Subject: Have a equivalent performing of goto
> Message-ID:
>       <CAH0GyZBqbubAJeJyDP601XJvaVZ0RTMv2AvYsr9Eb+1uNe1uLg@mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> How to equivalently perform goto in Bash ?
> illustrative
> ...
> echo some start
>
> if ((i=1)) ;then
>   goto thisFar
> fi
>
> echo foobar
>
>
> thisFar:
>
> echo go on
>
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 12 Jul 2023 11:13:08 -0400
> From: Greg Wooledge <greg@wooledge.org>
> To: help-bash@gnu.org
> Subject: Re: Have a equivalent performing of goto
> Message-ID: <ZK7DBNHnw3+TDzXS@wooledge.org>
> Content-Type: text/plain; charset=us-ascii
>
> On Wed, Jul 12, 2023 at 10:07:34PM +0700, Budi wrote:
>> How to equivalently perform goto in Bash ?
>
> You don't.
>
> Rewrite your control logic using while loops, for loops, if statements,
> case statements, functions, state variables, etc.
>
>> if ((i=1)) ;then
>>   goto thisFar
>> fi
>>
>> echo foobar
>>
>>
>> thisFar:
>>
>> echo go on
>
> So there's a block of code in the middle that you want to skip over,
> if some condition is met?  Wrap that whole middle section in an "if"
> statement.  You can also move it to a(nother) function if that'll help
> with readability.
>
> local skip=0
>
> if ((i == 1)); then
>     skip=1
> fi
>
> if ((!skip)); then
>     echo foobar
> fi
>
> echo go on
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Help-bash mailing list
> Help-bash@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-bash
>
>
> ------------------------------
>
> End of Help-bash Digest, Vol 141, Issue 8
> *****************************************
>



reply via email to

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