Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15478 > unrolled thread
| Started by | Greg Wooledge <wooledg@eeg.ccf.org> |
|---|---|
| First post | 2019-10-07 08:47 -0400 |
| Last post | 2019-10-07 08:47 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Is this a bug by any chance? Greg Wooledge <wooledg@eeg.ccf.org> - 2019-10-07 08:47 -0400
| From | Greg Wooledge <wooledg@eeg.ccf.org> |
|---|---|
| Date | 2019-10-07 08:47 -0400 |
| Subject | Re: Is this a bug by any chance? |
| Message-ID | <mailman.1215.1570452489.2651.bug-bash@gnu.org> |
On Sat, Oct 05, 2019 at 06:48:35PM +0000, George R Goffe via Bug reports for the GNU Bourne Again SHell wrote:
> I was expecting to see:
> 12345
> #!./bash -xv
> x="1 2 3 4 5"
> for z in "$x"
> do
> echo "$z"
> done
> exit 0
Not a bug. You've created a string of length 9 characters, and
you've told bash to iterate once, using this string as the contents of
variable z.
If you want to create a *list* and iterate over that list, one element
at a time, use arrays instead of string variables.
x=(1 2 3 4 5)
for z in "${x[@]}"; do
echo "$z"
done
See <https://mywiki.wooledge.org/BashGuide/Arrays> and
<https://mywiki.wooledge.org/BashFAQ/005>.
Back to top | Article view | gnu.bash.bug
csiph-web