gpt4 book ai didi

fish - 如何访问 fish 脚本中的剩余参数

转载 作者:行者123 更新时间:2023-12-03 09:14:18 26 4
gpt4 key购买 nike

my-fish-script a b c d

假设你想从第二个参数开始获取所有参数,所以 b c d .

在 bash 中,您可以使用 shift转储第一个参数并使用 "$@" 访问其余参数.

你将如何使用 fish shell 解决这个问题?

最佳答案

在fish 中,您的参数包含在$argv 中。列表。使用列表切片来访问一系列元素,例如$argv[2..-1]返回从第二个到最后一个的所有参数。

例如

function loop --description "loop <count> <command>"
for i in (seq 1 $argv[1])
eval $argv[2..-1]
end
end

用法
$ loop 3 echo hello world
hello world
hello world
hello world

关于fish - 如何访问 fish 脚本中的剩余参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24093649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com