【发布时间】:2014-03-08 10:02:18
【问题描述】:
在 bash 脚本中,find 的结果是
/path/to/file1.nrg
/path/to/file2.nrg
/path/to/file3.nrg
我有这个while循环:
流程预设
processpreset ()
{
x=$1
# Replace , by -o -iname for file types.
iname=" -o -iname \*."
# Find specified files. Eval allow var prst1_in with find.
eval "find "$fpath" -type f \( -iname \*."${prst_in[x]//,/$iname}" \) -size ${prst_lim_size[x]}" | sort | while read -r i
do
titles=$(HandBrakeCLI --input "$i" --scan |& grep -Po '(?<=DVD has )([0-9]+)')
if (( $titles > 1 )); then
echo "DVD has $titles title(s)"
fi
done
}
脚本停止后仅回显 1 次 File has 8 title(s),当使用 titles="8" 循环回显文件夹中的所有文件时。谁能指出我的错误?
编辑:什么对我有用,非常感谢 Anubhava
processpreset ()
{
x=$1
# Replace , by -o -iname for file types.
iname=" -o -iname \*."
# Find specified files. Eval allow var prst1_in with find.
eval "find "$fpath" -type f \( -iname \*."${prst_in[x]//,/$iname}" \) -size ${prst_lim_size[x]}" | sort | while read -r i
do
titles="$(echo ""|HandBrakeCLI --input "$i" --scan |& grep -Po '(?<=DVD has )([0-9]+)')"
if (( $titles > 1 )); then
echo "DVD has $titles title(s)"
fi
done
}
echo ""| 解决问题。
【问题讨论】:
-
但是你的 while 循环只是从标准输入读取变量。
-
从 HandBrake Manual 日志数据输出到标准错误编码进度信息(ETA、完成百分比、平均编码帧率等)输出到标准输出。为什么重定向会阻塞循环继续,不明白
-
我说的是
while read -r i,你是不是每次循环运行时都从终端读取i? -
@anubhava 我已经编辑了完整的代码,它回答了你的问题吗?
-
你从
ind $imgpath -type f \( -iname \*.iso -o -iname \*.nrg -o -iname \*.img \)" | sort命令得到了多少行?
标签: bash while-loop command io-redirection