How to access remaining arguments in a fish script

后端 未结 3 814
失恋的感觉
失恋的感觉 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:12

    The behaviour of the shift command can be simulated with set -e/--erase VARIABLE_NAME.

    The idea is to erase the first argument, then get the remaining arguments from the $argv list.

    For example

    function loop  --description "loop  "
      set count $argv[1]
      set --erase argv[1]
      for i in (seq 1 $count)
        eval $argv
      end
    end
    

    Usage

    $ loop 3 echo hello world
    hello world
    hello world
    hello world
    

提交回复
热议问题