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: Kerin Millar
Subject: Re: a sentense about set -k .. ?
Date: Fri, 30 Jun 2023 04:32:29 +0100

On Fri, 30 Jun 2023 04:34:08 +0200
alex xmb ratchev <fxmbsw7@gmail.com> wrote:

>        If the -k option is set (see the set builtin command below), then all
>        parameter assignments are placed in the environment for a command,
> not
>        just those that precede the command name.
> 
> 
>               -k      All arguments in the form of assignment statements are
>                       placed in the environment for a command, not just
> those
>                       that precede the command name.
> 
> its not echo $yo yo=7
> nor yo=7 echo $yo
> 
> in other words , i get not what it does ..
> so i ask for a sentense , two .. about it

It's an obsolete feature desiged for the original Bourne shell. It is 
completely and utterly useless and should be avoided at all costs. Here is an 
example of it in action.

$ bash -c 'args=("$@"); declare -p args' _ foo bar=123 baz
declare -a args=([0]="foo" [1]="bar=123" [2]="baz")

So far so good. Now let's turn on the 'keyword' feature.

$ set -k
$ bash -c 'args=("$@"); declare -p args' _ foo bar=123 baz
declare -a args=([0]="foo" [1]="baz")

What happened to bar=123? Let's find out.

$ bash -c 'args=("$@"); declare -p args bar' _ foo bar=123 baz
declare -a args=([0]="foo" [1]="baz")
declare -x bar="123"

This shows that bar=123 was seen to be in the form of an assignment statement 
and was reappropriated as an environment variable to be propagated to the 
subprocess.

-- 
Kerin Millar



reply via email to

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