Search code examples
fish

for loop in fish shell only goes a maximum of 3 times


I'm using fish shell to do a simple for loop. For some reason it only iterates three times instead of a 100 (or whatever I put in there). What am I doing wrong?

error ➜  for i in seq 1 100
             echo hi
         end
hi
hi
hi
error ➜ 

Note that running seq 1 100 will -as expected- output numbers from 1 to 100.

Here's my fish version:

error ➜  fish --version
fish, version 3.0.2

Solution

  • That's because you're not launching the seq command.

    You are doing this

    for i in "seq" "1" "100"
    

    when you want to do this

    for i in (seq 1 100)
    # .......^.........^  command substitution