[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Command Substitution
From: |
Davide Brini |
Subject: |
Re: [Help-bash] Command Substitution |
Date: |
Sun, 24 Nov 2013 12:10:26 +0100 |
On Sun, 24 Nov 2013 12:34:57 +0800, Kevin Connor Arpe <address@hidden>
wrote:
> Hello,
>
> I am seeking clarification about the Bash 4.2 man page. I downloaded
> the latest source and built a binary from scratch on Linux.
>
> Section "Command Substitution" has the following sentence:
> "If the substitution appears within double quotes, word splitting and
> pathname expansion are not performed on the results."
>
> Unless I misunderstand, this sentence is inconsistent with the following:
> $ bash
> $ echo $BASH_VERSION
> 4.2.0(2)-release
> $ var="data
> > more data"
> $ echo $var
> data more data
This is because word splitting is performed on the unquoted variable $var.
> $ echo "[$var]"
> [data
> more data]
> # ^^^ Should be '[data more data]'?
Only if word splitting was performed. But it's not performed, since the
variable appears within double quotes.
> $ var2=$(echo "$var")
Word splitting is NOT performed upon assignment (this is noted elsewhere in
the manual), so var2 is an exact copy of var.
> $ echo $var2
> data more data
Again, word splitting is performed on the unquoted variable $var2.
> $ echo "[$var2]"
> [data
> more data]
> # ^^^ Should be '[data more data]'?
Same as above. var2 is still
data
more data
since it's an exact copy of $var.
> $ bash
> $ var3="$(echo "$var")"
> $ echo $var3
> data more data
> $ echo "[$var3]"
> [data
> more data]
Same as previous example, but with (in this case unnecessary, but not
harmful either) quotes around the assignment.
--
D.