24

I want to limit sequence in for loop. All my tries were unsecsessfull. What Am I doing wrong?

I thought that this should work:

for x in ((seq 100)[50..55])
  echo $x
end
Cyrus
  • 84,225
  • 14
  • 89
  • 153
Michael Karavaev
  • 1,439
  • 1
  • 13
  • 18

2 Answers2

55

With fish:

for i in (seq 50 55); echo "$i"; end

Output:

50
51
52
53
54
55
Cyrus
  • 84,225
  • 14
  • 89
  • 153
5

You have one too many pairs of parenthesis. In fish parenthesis do what $(command) and `command` do in bash or zsh. So just do

for x in (seq 100)[50..55]
    echo $x
end

And, of course, for this specific example you don't even need the slice notation since you can just tell the seq command to begin and end with the desired values.

Kurtis Rader
  • 6,734
  • 13
  • 20