On Thu, Jun 29, 2023, at 10:57 PM, Greg Wooledge wrote:
> You need to use a
> command that actually *uses* the yo environment variable.
>
> unicorn:~$ awk 'BEGIN {print ENVIRON["yo"]}' yo=7
>
> unicorn:~$ set -k
> unicorn:~$ awk 'BEGIN {print ENVIRON["yo"]}' yo=7
> 7
As a corollary, "yo=7" is no longer passed to the command as an
argument:
bash-5.2$ set -x
bash-5.2$ awk 'END { print "yo is", yo }' yo=7 </dev/null
+ awk 'END { print "yo is", yo }' yo=7
yo is 7
bash-5.2$ set -k
+ set -k
bash-5.2$ awk 'END { print "yo is", yo }' yo=7 </dev/null
+ yo=7
+ awk 'END { print "yo is", yo }'
yo is
> I've never seen anyone use this set -k "feature". I cannot see any good
> reason for it to continue to exist. Looks extremely legacy-ish.
Even POSIX didn't take it!
The following "set" options were omitted intentionally with the
following rationale:
-k
The -k flag was originally added by the author of the
Bourne shell to make it easier for users of pre-release
versions of the shell. In early versions of the Bourne
shell the construct "set name=value" had to be used to
assign values to shell variables. The problem with -k is
that the behavior affects parsing, virtually precluding
writing any compilers. To explain the behavior of -k, it
is necessary to describe the parsing algorithm, which is
implementation-defined. For example:
set -k; echo name=value
and
set -k
echo name=value
behave differently. The interaction with functions is
even more complex. What is more, the -k flag is never
needed, since the command line could have been reordered.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set
--
vq