bug-bash
[Top][All Lists]
Advanced

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

Re: Command substitution


From: felix
Subject: Re: Command substitution
Date: Wed, 3 Jun 2020 08:38:50 +0200
User-agent: Mutt/1.10.1 (2018-07-13)

Quoting is useless when assigning variable from ouptut of command or
another variable:

    $ foo=1 2 3 4 
    bash: 2: command not found

Ok. But

    $ foo=$(seq 1 3)
    $ declare -p foo
    declare -- foo="1
    2
    3"

    $ foo="$(seq 1 3)"
    $ declare -p foo
    declare -- foo="1
    2
    3"

No difference with or without double-quote.

    $ bar=$foo
    $ declare -p bar
    declare -- bar="1
    2
    3"

    $ bar="$foo"
    $ declare -p bar
    declare -- bar="1
    2
    3"

Again, double-quoting is useless.

But for commands:

    $ printf "<%s>\n" $foo
    <1>
    <2>
    <3>
    $ printf "<%s>\n" "$foo"
    <1
    2
    3>

Same than

    $ printf "<%s>\n" $(seq 1 3) 
    <1>
    <2>
    <3>
    $ printf "<%s>\n" "$(seq 1 3)"
    <1
    2
    3>

Unfortunely, I don't retrieve this behaviour in man page.

On Tue, Jun 02, 2020 at 09:44:45PM -0400, 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?
> 
> Dale
> 

-- 
 Félix Hauri  -  <felix@f-hauri.ch>  -  http://www.f-hauri.ch



reply via email to

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