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

Viewed 364

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
2 Answers

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

hmmm so the answer to my question is very simple.

I should have (seq 1 100) instead of seq 1 100.

It needs to be enclosed in brackets to have the seq command evaluated. Instead, what I just gave fish is an array of three strings ("seq" "1" "100") who happened to look like a command lol.

So yeah I am not a very intelligent person.

Related