我正在尝试使用 vim
打开当前目录下的每个 txt
文件。
find . -name "*.txt" -print | while read aline; do
read -p "start spellchecking fine: $aline" sth
vim $aline
done
在 bash
中运行它会报错
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.
任何人都可以解释可能出现的问题吗?另外,我打算在使用 vim 之前使用 read -p
进行提示,但没有成功。
最佳答案
尝试:
vim $( find . -name "*.txt" )
要修复您的解决方案,您可以(可能)这样做:
find . -name "*.txt" -print | while read aline; do
read -p "start spellchecking fine: $aline" sth < /dev/tty
vim $aline < /dev/tty
done
问题是整个 while 循环都从 find 获取输入,而 vim 继承了那个管道作为它的标准输入。这是让 vim 的输入来自您的终端的一种技术。 (不过,并非所有系统都支持 /dev/tty
。)
关于bash - 如何使用 vim 打开目录下的每个 .txt 文件(使用 Bash),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13555834/