我的脚本很简单:
while read -r key; do
rg --glob='!some_dir' --fixed-strings --quiet "$key" || echo "$key"
done < <(grep 'some_pattern' some/file | cut -d'"' -f2)
我希望使用此bash脚本来打印未使用的键。但是,此循环在每次运行的第一次迭代后都会中断。为什么以及如何解决?谢谢:D
这看起来像是经典案例,当命令while..read
循环运行也从标准输入开始时。你期望的输出grep
将由while循环迭代的方式来读了,但由于某些原因,你的命令rg
是也来自同一个阅读。
关闭为
rg --glob='!some_dir' --fixed-strings --quiet "$key" < /dev/null || echo "$key"
或使用其他文件描述符
while read -r -u 3 key; do
rg --glob='!some_dir' --fixed-strings --quiet "$key" || echo "$key"
done 3< <(grep 'some_pattern' some/file | cut -d'"' -f2)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句