gpt4 book ai didi

linux - Bash +在用户提示后打印默认字符

转载 作者:太空宇宙 更新时间:2023-11-04 10:57:30 26 4
gpt4 key购买 nike

-我做了一个这样的 bash 函数:

find_stuff () {
list=`find $SEARCHPATH -type f -user $USERID -mmin -$SOMETIME -not -path '*/\.*' -exec ls -1rt {} \+`
if [ -n "$list" ]; then
for i in $list; do
echo "Found item: "$i""; printf 'Is this ok? y/n [y]:'
read arg
case "arg" in
y|\Y)
do_stuff
;;
n|\N)
continue
;;
*)
echo "Please type 'y'=yes or 'n'=no, -exiting..."
exit 0
;;
esac
done
else
echo "No items found, exiting..."
exit 0
fi
}

现在我想像这样这样为最终用户扩展功能:

./finditems.sh

试图找到东西,然后在确认后做一些事情。

Found item: /dir/mod.item

Is this ok? y/n [y]:y

如何在用户的 shell 提示符下打印“用户可移动”y 字符?

我尝试了 read -p 的一些变体,但它没有给我想要的结果。

最佳答案

对于 bash 4+(我相信),如果您将 readline 与 read 一起使用,那么您可以使用 -i text 参数来读取预置输入。

关于linux - Bash +在用户提示后打印默认字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28301089/

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