8

Is there a way I can get the array size in fish shell?

The exact problem I have at hand is that I would like to do some operations on all array elements except the first one. So I was trying to find the size so that I can loop from 2 to $array_size.

If it is not possible, what is an alternative method?

2 Answers 2

12

count will print the number of elements. But if you want to just skip the first element, you can use slices:

> set arr one two three
> echo $arr
one two three
> echo $arr[2..-1]
two three
9

using the count command which is a command built into fish.

Example:

$ count $PATH
11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.