help-bash
[Top][All Lists]
Advanced

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

Re: a sentense about set -k .. ?


From: Lawrence Velázquez
Subject: Re: a sentense about set -k .. ?
Date: Thu, 29 Jun 2023 23:31:35 -0400
User-agent: Cyrus-JMAP/3.9.0-alpha0-499-gf27bbf33e2-fm-20230619.001-gf27bbf33

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



reply via email to

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