How to access remaining arguments in a fish script

后端 未结 3 751
失恋的感觉
失恋的感觉 2021-01-31 15:55
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

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 16:09

    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  "
      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
    

提交回复
热议问题