Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate for loop with limiting sequence in fish shell

Tags:

for-loop

fish

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
like image 592
Michael Karavaev Avatar asked Mar 22 '16 05:03

Michael Karavaev


2 Answers

With fish:

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

Output:

50
51
52
53
54
55
like image 167
Cyrus Avatar answered Oct 13 '22 21:10

Cyrus


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.

like image 5
Kurtis Rader Avatar answered Oct 13 '22 23:10

Kurtis Rader