Search code examples
named-parametersfish

Can I pass named parameters to a fish script?


I have learnt about using $argv to access parameter values passed to a fish script (or function). However, this approach requires positional arguments. Is it possible to pass named parameters in an arbitrary order, and extract them based on their name?

For example, the following two calls would be equivalent:

favourite_shell best=fish ideological_war=start

favourite_shell ideological_war=start best=fish

Solution

  • It's the future and you can now use argparse: https://fishshell.com/docs/current/cmds/argparse.html

    argparse is the outcome of the Github discussion mentioned in the original answer (https://github.com/fish-shell/fish-shell/issues/478), which has now been closed.