[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Command substitution
From: |
Eli Schwartz |
Subject: |
Re: Command substitution |
Date: |
Tue, 2 Jun 2020 22:02:55 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 |
On 6/2/20 9:44 PM, Dale R. Worley wrote:
> Naively, I expect that
>
> FOO="$( command2 )"
> command1 $FOO
>
> has the same effect as
>
> command1 $( command2 )
>
> and
>
> FOO="$( command2 )"
> command1 "$FOO"
>
> has the same effect as
>
> command1 "$( command2 )"
>
> Has anyone pushed the boundaries of this and can tell me whether there
> are gotchas?
What boundaries were you expecting? If this is related to the thread
about the value of $? after command substitution in variable assignment
vs. command arguments... that's already a gotcha according to many
people. Despite being both documented and logical.
Aside for that, obviously in one case you don't have a "FOO" variable in
the shell environment, which does seem like a fairly major difference as
it's a very common pattern for people to reuse the results of command
substitution multiple times.
Perhaps you meant to say "executes the same command process" instead of
"has the same effect"?
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User
signature.asc
Description: OpenPGP digital signature