How to get arguments in Fish script?
·
132 words
·
1 minute read
Here is a command with 3 arguments.
myfunc one two "third arg"
How to get each argument in Fish script/function.
- to get all arguments as one string/text, use
$argv
. - to get first argument, use
$argv[1]
. - to get second argument, use
$argv[2]
. - to get the function name or the script name, use
$argv[0]
. - to the remaining three arguments after two :
myfunc one two three four five
, use$argv[3..-1]
as-1
is the end of arguments. - to echo/print the arguments, use
eval
like thiseval $argv[3..-1]
.
For example, I created gitp Fish function to shorten the git steps.
function gitp --description "gitp <message>"
git add -Av
git commit -m $argv
git push
end
I hope this helps you. You know someone will benefit from this, share it with him/her, a friend or colleage.