my-fish-script a b c d
Say you want to get the all arguments from the second argument onwards, so b c d
.
In bash you can use shift
to dump the first argument and access the remaining ones with "$@"
.
How would you solve the problem using the fish shell?
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> .
You can pass more than one argument to your bash script. In general, here is the syntax of passing multiple arguments to any bash script: script.sh arg1 arg2 arg3 … The second argument will be referenced by the $2 variable, the third argument is referenced by $3 , .. etc.
Fish is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. Fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure.
Configuration¶ To store configuration write it to a file called ~/. config/fish/config.
In fish, your arguments are contained in the $argv
list. Use list slicing to access a range of elements, e.g. $argv[2..-1]
returns all arguments from the second to the last.
For example
function loop --description "loop <count> <command>" for i in (seq 1 $argv[1]) eval $argv[2..-1] end end
Usage
$ loop 3 echo hello world hello world hello world hello world
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With