[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Please help clarify bash this common found code
From: |
Budi |
Subject: |
Re: Please help clarify bash this common found code |
Date: |
Fri, 20 Oct 2023 18:35:37 +0700 |
Andreas Kähäri
Kerin Millar
Thanks billion !
On 10/20/23, Kerin Millar <kfm@plushkava.net> wrote:
> On Fri, 20 Oct 2023 13:33:03 +0700
> Budi <budikusasi@gmail.com> wrote:
>
>> Please help clarify bash this common yet doubtful line
>>
>> So often read or found a variable definition (or/and declaration) is
>> at the start preceding every command/code, one terminated by shel
>> terminator the other not
>>
>> This merely illustration, what is the definitive function/behaviour on
>> e.g. each of
>>
>> FOO=bar ; find /usr
>
> This comprises two simple commands [1] [2], one of which is to be executed
> after the other.
>
>>
>> and
>>
>> FOO=bar make Makefile
>
> This is a solitary simple command.
>
>>
>> Please crystal clearly elaborate it
>>
>
> It is clearly explained by the manual [3]. A particularly important
> distinction is that, "If no command name results, the variable assignments
> affect the current shell environment. Otherwise, the variables are added to
> the environment of the executed command and do not affect the current shell
> environment."
>
> Thus:
>
> $ FOO=bar
> $ printenv FOO # FOO wasn't exported; environment of command/subprocess
> unaffected
> $ declare -p FOO # current shell environment affected
> declare -- FOO="bar"
> $ unset -v FOO
>
> Conversely:
>
> $ FOO=bar printenv FOO
> bar
> $ declare -p FOO # current shell environment unaffected
> bash: declare: FOO: not found
>
> [1] https://www.gnu.org/software/bash/manual/html_node/Simple-Commands.html
> [2]
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01
> [3]
> https://www.gnu.org/software/bash/manual/html_node/Simple-Command-Expansion.html
>
> --
> Kerin Millar
>