Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16357

Re: Command substitution

From felix <felix@f-hauri.ch>
Newsgroups gnu.bash.bug
Subject Re: Command substitution
Date 2020-06-03 08:38 +0200
Message-ID <mailman.1033.1591166340.2541.bug-bash@gnu.org> (permalink)
References <87mu5kgbxu.fsf@hobgoblin.ariadne.com> <20200603063850.GH8205@medium.hauri>

Show all headers | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Command substitution felix <felix@f-hauri.ch> - 2020-06-03 08:38 +0200

csiph-web