linux - Bash 读取用户 y/n 答案不起作用(在循环读取查找输出时读取内部命令)

标签 linux bash

我这里有个问题。似乎我的 Bash 脚本忽略了 dodone 之间的所有内容。不知道为什么,也许你会看到问题。提前致谢。

katalogas=$1
find $katalogas -type f -mtime +3 | while read $failai
do
read -p "Run command $foo? [yn]" answer
if [[ $answer = y ]] ; then
  rm $failai
fi
done

最佳答案

尝试替换

read -p "Run command $foo? [yn]" answer

通过

read -p "Run command $foo? [yn]" answer </dev/tty

避免从标准输入读取。

更新 Will 的建议:

katalogas="$1"
read -p "Run command $foo? [yn]" answer
if [[ $answer = y ]] ; then
  find "$katalogas" -type f -mtime +3 | while read failai
  do
    rm "$failai"
  done
fi

关于linux - Bash 读取用户 y/n 答案不起作用(在循环读取查找输出时读取内部命令),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30018756/

相关文章:

c++ - Ncurses - 如何将某些内容添加到输入缓冲区中

linux - 查找不包含 "*.sql"文件的目录

c - 如何使我的 Linux C 程序可以从 bash 访问

bash - awk/sed : How to do a recursive find/replace of a string in files with a certain file extension?

Java - ArrayList remove() 未删除

linux - 如何杀死已经使用源执行的脚本?

BASH 命令提示符 : add characters behind command

bash - 如何查找被触发命令的日期明智历史

linux - 英特尔 OpenCL Beignet 问题

linux - SSH多终端MAC