Re: for loop with variable

Roman Perepelitsa <[email protected]> Mon, 11 May 2026 19:11:55 +0200
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CAN=4vMrPSXyPkSX+bfZ0J8tuyujj-wU5Ly6Ba9073ERNb25p3Q@mail.gmail.com>
On Mon, May 11, 2026 at 6:45=E2=80=AFPM Ray Andrews <[email protected]=
> wrote:
>
> % var=3D" a b c "
>
> % for aa in $=3Dvar; do echo $aa; done
> a
> b
> c
>
> % for aa in [a-c]; do echo $aa; done
> c
>
> ... In the last 'for' it wants to find files whereas in the previous it k=
nows it's looking at text.  Could the previous be done on one line?  That i=
s, the range '[a-c]' would be understood to be just text, not a file glob?

{a..c} expands to a b c. You can iterate over that.

Roman