37

In bash, I can do the following

$ echo bunny{1..6}
bunny1 bunny2 bunny3 bunny4 bunny5 bunny6

Is there a way to achieve the same result in fish?

workflow
  • 2,536
  • 2
  • 14
  • 11
  • 4
    As an aside for those less familiar with `fish`: `fish` does support brace expansion, but only with _lists_ (e.g., `echo b{ar,az}`), not _ranges_. – mklement0 May 04 '15 at 15:26

1 Answers1

62

The short answer is echo bunny(seq 6)

Longer answer: In keeping with fish's philosophy of replacing magical syntax with concrete commands, we should hunt for a Unix command that substitutes for the syntactic construct {1..6}. seq fits the bill; it outputs numbers in some range, and in this case, integers from 1 to 6. fish (to its shame) omits a help page for seq, but it is a standard Unix/Linux command.

Once we have found such a command, we can leverage command substitutions. The command (foo)bar performs command substitution, expanding foo into an array, and may result in multiple arguments. Each argument has 'bar' appended.

ridiculous_fish
  • 17,273
  • 1
  • 54
  • 61
  • 7
    @chepner: It doesn't matter. fish shell automatically defines `seq` if it doesn't exist, as certain parts of fish source depend on it to exist. – Konrad Borowski Dec 31 '13 at 15:15
  • 9
    Since this is the first result for "fish brace expansion"... It is worth noting that fish does do simple brace expansion with commas. e.g. `echo {foo,bar}` or `mkdir --parents /tmp/{folder1,folder2,folder3}` results in /tmp/folder1, /tmp/folder2, /tmp/folder3. More info @ http://fishshell.com/docs/2.0/index.html#expand – Elijah Lynn Mar 09 '17 at 23:37
  • @wviana Try `jot -c 26 a z 1` – Panic Nov 25 '17 at 13:51
  • @wviana: a self contained answer: `printf '%b' (printf '\\\\x%02X ' (seq 97 122))` – enzotib Apr 26 '19 at 07:45
  • 2
    What about `touch file{01..10}`, how do you do that in `fish` shell? – 109149 Nov 08 '20 at 11:26
  • 4
    You can pass a format string to seq. `touch file(seq -f %02g 10)` – ridiculous_fish Nov 09 '20 at 17:06
  • 2
    @109149 this should also work `touch file(seq -w 10)` – Theo C Oct 23 '21 at 09:27