[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is this a bug by any chance?
From: |
|
Subject: |
Re: Is this a bug by any chance? |
Date: |
Sat, 5 Oct 2019 20:43:20 +0100 |
On Sat, 5 Oct 2019 18:48:35 +0000 (UTC)
George R Goffe via Bug reports for the GNU Bourne Again SHell
<bug-bash@gnu.org> wrote:
> Hi,
>
> I just built the latest bash in an effort to determine if thie script shows a
> bug or a ufu. Can you help me please?
>
> I was expecting to see:
> 12345
>
> Best regards AND thanks for your help,
>
> George...
>
> #!./bash -xv
> x="1 2 3 4 5"
> + x='1 2 3 4 5'
> for z in "$x"
> do
> echo "$z"
> done
> + for z in "$x"
> + echo '1 2 3 4 5'
> 1 2 3 4 5
> exit 0
> + exit 0
>
>
It's definitely not a bug. Quoting the expansion inhibits word splitting. Your
loop iterates once over a single word. Said word is conveyed to echo as a
single argument. In this case, said argument is printed by echo, with the
addition of a newline character. If your ultimate intent is to store an
arbitrary list of strings in a variable prior to iterating over them, you
should use an array variable instead. As such, this would be a topic better
suited to the help-bash list.
--
Kerin Millar