Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get array size in fish shell?

Tags:

fish

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?

like image 256
Adham Zahran Avatar asked Apr 24 '18 19:04

Adham Zahran


People also ask

How do you find the length of an array in Linux?

To get the length of an array, we can use the {#array[@]} syntax in bash. The # in the above syntax calculates the array size, without hash # it just returns all elements in the array.

Where is the fish shell config file?

fish files in ~/. config/fish/conf. d/ . See Configuration Files for the details.

How do I customize my fish prompt?

To create a custom prompt create a file ~/. config/fish/functions/fish_prompt. fish and fill it with your prompt. Is there a way to save multiple prompts, or add to the list of available prompts that are displayed when you run fish_config?

How do I run a fish shell script?

To be able to run fish scripts from your terminal, you have to do two things. Add the following shebang line to the top of your script file: #!/usr/bin/env fish . Mark the file as executable using the following command: chmod +x <YOUR_FISH_SCRIPT_FILENAME> .


2 Answers

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
like image 186
ridiculous_fish Avatar answered Sep 19 '22 14:09

ridiculous_fish


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

Example:

$ count $PATH
11
like image 25
Adham Zahran Avatar answered Sep 23 '22 14:09

Adham Zahran