gpt4 book ai didi

user-input - 如何在 fish shell 中获得用户确认?

转载 作者:行者123 更新时间:2023-12-04 00:10:21 27 4
gpt4 key购买 nike

我正在尝试收集用户在鱼壳脚本中的输入,尤其是以下常见形式的用户输入:

This command will delete some files. Proceed (y/N)?


经过一番搜索后,我仍然不确定如何干净地执行此操作。

这些是在鱼中做的特殊方法吗?

最佳答案

我所知道的最好方法是使用内置的read。如果您在多个地方使用此功能,则可以创建此帮助程序功能:

function read_confirm
while true
read -l -P 'Do you want to continue? [y/N] ' confirm

switch $confirm
case Y y
return 0
case '' N n
return 1
end
end
end


并在脚本/函数中像这样使用它:

if read_confirm
echo 'Do stuff'
end


请参阅文档以了解更多选项:
https://fishshell.com/docs/current/commands.html#read

关于user-input - 如何在 fish shell 中获得用户确认?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16407530/

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