[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: improving '{...}' in bash?
From: |
Martin D Kealey |
Subject: |
Re: improving '{...}' in bash? |
Date: |
Tue, 23 Jul 2024 19:10:23 +1000 |
On Tue, 23 Jul 2024, 15:50 Harald Dunkel, <harald.dunkel@aixigo.com> wrote:
> Hi folks,
>
> This feels weird:
>
Did you read the manual before trying any of these?
% echo x{1,2}x
> x1x x2x
> % echo x{1}x
> x{1}x
>
Why are you trying to use a multiplier syntax when you don't have more than
one option?
Be aware that brace expansion occurs before variable expansion, so you
can't put a brace-style list in a variable and then expect it to be
expanded; brace expansion is only intended to be used with literals, and
nobody would both to write such a literal.
Besides this, the shell is *required* not to replace braces *except* for
the few express patterns described in the manual.
% echo x{1..3,5}x
> x1..3x x5x
>
That's what I would expect, yes.
I would have expected "x1x" and "x1x x2x x3x x5x".
Not when it's missing the second pair of braces; perhaps you intended to
use `echo x{{1..3},5}x`?
-Martin