help-bash
[Top][All Lists]
Advanced

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

Re: Possible bug but looking for help before bothering a dev


From: Laurent Lyaudet
Subject: Re: Possible bug but looking for help before bothering a dev
Date: Wed, 4 Mar 2026 20:39:57 +0100

Le mer. 4 mars 2026 à 20:21, Chet Ramey <chet.ramey@case.edu> a écrit :
>
> On 3/4/26 2:00 PM, Laurent Lyaudet wrote:
>
> > not_funny2(){
> >    # The {} syntax doesn't work for variables affectation.
> >    declare -i LFBFL_i_result=0
> >    echo "$1" | {
> >      [[ "$1" == "hahaha" ]]
> >      LFBFL_i_result=$?
> >    }
> >    # shellcheck disable=SC2248
> >    return ${LFBFL_i_result}
> > }
> >
> > Here is what I obtain:
> >
> > $ not_funny1 hahaha && echo "abcd"
> > abcd
> > $ not_funny1 hihihi && echo "abcd"
> > $ not_funny2 hahaha && echo "abcd"
> > abcd
> > $ not_funny2 hihihi && echo "abcd"
> > abcd
> >
> > Surprisingly, it behaves like a normal subshell
>
> Why is this surprising? All elements of the pipeline are executed in
> subshells.
>
> --
> ``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/

Because {} doesn't create a subshell outside of pipeline
and even in a pipeline {} and () doesn't work the same way.
If the rule {} is equivalent to () when in a pipeline,
then exit command inside {} would do the same thing inside ()
and that's not the case as explained in the results of my tests
that are in a previous email in the same discussion.



reply via email to

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