1

This works as expected:

$ echo file-{00..03}
file-00 file-01 file-02 file-03

This does not do what I wanted:

$ start=00
$ end=03
$ echo file-{$start..$end}
file-{00..03}

The reason is that brace expansion is performed before any other epansion.

In my case, the sequence limits are in the variables start and end.

Any clever way to hack my way around this?

blueFast
  • 41,341
  • 63
  • 198
  • 344
  • You have the sequence limits in the variables already, do you care to use `for` loop instead of brace expansion? – rustyhu Nov 17 '21 at 05:27
  • 1
    Does this answer your question? [Brace expansion with variable?](https://stackoverflow.com/questions/19432753/brace-expansion-with-variable) – rustyhu Nov 17 '21 at 05:34
  • @rustyhu No for loop, I need to make use of `xargs` to process the `echo` output (to avoid invoking thousands of processes) – blueFast Nov 17 '21 at 05:39
  • Bash does not provide for use of variables within brace expansion. There are hacks that you can use to make it work -- but when you find yourself doing so, it should tell you to refactor your script instead. – David C. Rankin Nov 17 '21 at 05:41
  • @DavidC.Rankin major refactoring is out of the question. I need to hack my way around in this particular statement - the cleaner, the better – blueFast Nov 17 '21 at 05:43
  • @rustyhu yepp, that answer provides a couple of options, including my eval. Thanks! – blueFast Nov 17 '21 at 05:44
  • It's doable with `eval` as you know. Howerver make sure whatever you generate isn't used with `rm` or other commands if the expression inadvertently expands to `/` (or the like) – David C. Rankin Nov 17 '21 at 05:45

1 Answers1

1

I have this:

$ eval echo file-{$start..$end}
file-00 file-01 file-02 file-03

But I am open to less ugly suggestions.

blueFast
  • 41,341
  • 63
  • 198
  • 344