fish

How do I translate this `for` loop for the fish shell?


I'm translating a script from Z shell to Fish, and I've got this one part I can't figure out how to translate:

  for (( i=0; i < $COLUMNS; i++ )); do
    printf $1
  done

The only documentation for for loops I can find in Fish is for this kind. How would I do this in Fish?


Solution

  • It appears that the Fish shell does not have that kind of for loop, but instead requires you to take a different approach. (The philosophy is apparently to rely on as few syntactic structures and operators as possible, and do as much with commands as possible.)

    Here's how I did it, although I assume there are better ways:

    for CHAR in (seq $COLUMNS)
      printf $argv[1]
    end
    

    This appears inside a function, hence the $argv[1].