[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Effect of prefixed assignments on built-ins
From: |
Chet Ramey |
Subject: |
Re: Effect of prefixed assignments on built-ins |
Date: |
Wed, 3 Jul 2024 10:06:25 -0400 |
User-agent: |
Mozilla Thunderbird |
On 6/30/24 1:18 PM, Jens Schmidt wrote:
Hello list,
I always get baffled about the following difference in behavior:
[~]$ echo $BASH_VERSION
5.2.15(1)-release
[~]$ IFS=foo read a b c <<< "afbocoo"
[~]$ echo "<$a:$b:$c>"
<a:b:coo>
[~]$ IFS=foo export | grep IFS
<no result>
Both "read" and "export" are built-ins, but the prefixed assignment
"IFS=foo" affects only "read".
The assignment preceding the builtin only affects the environment
the builtin sees. `read' uses IFS, and finds it in its temporary
environment; `export' does not, since it's not a variable that has been
given the export attribute. There's a little variation out there on the
behavior of export (looking at you, ksh93), so POSIX makes it unspecified.
The POSIX twist is that assignments preceding special builtins (of which
export is one and read is not) persist in the shell environment after the
builtin completes. Not that that would matter in your example, since you
run export in a subshell.
I couldn't find anything in the man page explaining that. I also have
tried searching the net, but the search terms I tried are all a bit too
general to give helpful results.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01
--
``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/
OpenPGP_signature.asc
Description: OpenPGP digital signature