HandBrakeCLI命令在while循环中断?

时间:2014-02-10 21:08:07

标签: bash while-loop command io-redirection

在bash脚本中,find的结果是

/path/to/file1.nrg
/path/to/file2.nrg
/path/to/file3.nrg

我有这个循环:

进程预设

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 ""|解决问题。

1 个答案:

答案 0 :(得分:3)

好的尝试这个脚本:

while read -r i
do
        echo "i is: $i"
        titles="$(echo ""|HandBrakeCLI --input "$i" --scan | grep -Po '(?<=DVD has )([0-9]+)')"
        if (( titles > 1 )); then
           echo "DVD has $titles title(s)"
        fi
done < <(find "$imgpath" -type f \( -iname \*.iso -o -iname \*.nrg -o -iname \*.img \) | sort)