HandBrakeCLI command break while loop?

2019-07-13 22:57发布

问题:

In a bash script, result of find is

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

i have this while loop:

process preset

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
}

the script only echo 1 time File has 8 title(s) after it stop, when using titles="8" the loop echo for all files in folder. Can anyone point me my error please?

EDIT: what work for me, many thanks 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
}

the echo ""| fix the problem.

回答1:

ok try this script:

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)