[Top][All Lists]

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

Re: Is this a bug by any chance?

From: Greg Wooledge
Subject: Re: Is this a bug by any chance?
Date: Mon, 7 Oct 2019 08:47:37 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

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"

See <https://mywiki.wooledge.org/BashGuide/Arrays> and

reply via email to

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