help-bash
[Top][All Lists]
Advanced

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

Re: why does </proc/self/environ not work in bash?


From: Grisha Levit
Subject: Re: why does </proc/self/environ not work in bash?
Date: Tue, 13 Feb 2024 10:39:59 -0500

On Tue, Feb 13, 2024, 10:16 Zachary Santer <zsanter@gmail.com> wrote:

> On Tue, Feb 13, 2024 at 9:33 AM Chet Ramey <chet.ramey@case.edu> wrote:
>
> > This sounds like another case of "I can't imagine it happening, so it
> must
> > not be happening."
> >
>
> But we've not reached the point where this would be considered a bug,
> because you know it was intentionally implemented this way?
>
> Bash has behaved this way forever, and this isn't convincing enough to
> > change that aspect of its behavior.
> >
>
> The behavior even differs between redirections from builtin commands vice
> external commands. Without considering implementation details, it just
> seems arbitrary.
>
> Should
> printf '%s\n' "whatever" > "$(( i++ ))-file.txt"
> behave differently than
> /usr/bin/printf '%s\n' "whatever" > "$(( i++ ))-file.txt"
> ?
>

Intuitive or not, this has been the established behavior, and script
writers who care about side effects of expansions in redirects have been
writing to code that does the right thing given the current implementation.

Note that it's possible to force the redirect to expand in either way, by
using a grouping construct for an external command (or a subshell for a
builtin).

$ i=0; true >$((i++)); echo $i
1

$ i=0; (true) >$((i++)); echo $i
0

$ i=0; env true >$((i++)); echo $i
0

$ i=0; { env true; } >$((i++)); echo $i
1


reply via email to

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