Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15983

Re: builtin echo vs /bin/echo appears to affect variable scope

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: builtin echo vs /bin/echo appears to affect variable scope
Date 2020-03-02 15:01 -0500
Message-ID <mailman.1925.1583179283.2412.bug-bash@gnu.org> (permalink)
References <CAAHpriP0ZosuQ7=5_F294UxzLb5ynbECCeqFoQK8Ex_GDkFGgw@mail.gmail.com> <c955eb8e-44b8-4aae-d9a9-64864a506709@case.edu>

Show all headers | View raw


On 3/2/20 2:54 PM, Keith Thompson wrote:
> From: kst
> To: bug-bash@gnu.org
> Subject: echo vs /bin/echo appears to affect variable scope
> 
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
> uname output: Linux bomb20 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11
> 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
> 
> Bash Version: 5.0
> Patch Level: 16
> Release Status: release
> 
> Description:
> The original test case was a small script in this answer on Stack Overflow:
> https://stackoverflow.com/a/60480960/827263
> 
> I've narrowed it down to two scripts that differ only in
> using "echo" vs.  "/bin/echo".  With the built-in "echo",
> $i is correctly incremented.  With the external "/bin/echo",
> $i appears to be 0 on each iteration.
> 
> Moving the "((i++))" into a separate command also works around
> the bug.

It's not a bug. That expansion is performed as part of a redirection;
redirections are performed in subshells when the simple command they
affect is run in a subshell.

-- 
``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/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: builtin echo vs /bin/echo appears to affect variable scope Chet Ramey <chet.ramey@case.edu> - 2020-03-02 15:01 -0500

csiph-web