Search code examples
bashxargs

Bash Script with Prompts from Xargs?


I have a script I am trying to run:

#!/bin/bash
echo "Please enter desired kbps example 1000 for 1000kbps: "
read desired
echo "Please enter minimum kbps: "
read minrate
echo "Please enter maximum kbps: "
read maxrate

for i; do
filename=$(basename "$i")
extension="${filename##*.}"
filename="${filename%.*}"
size=k
    d=$(dirname "$i")
#    b=$(basename "$i")
ffmpeg -i "$i" -c:v hevc_nvenc -preset medium -crf 28 -b:v $desired$size -minrate $minrate$size -maxrate $maxrate$size -bufsize 25M -c:a copy "$d/X265_$filename.mp4"
mv "$i" "$d/zzz_$filename.$extension"
done

Using this find command with xargs:

find ./ -type f -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\)" -print0 | xargs -0 /root/batch.sh

I want it to prompt me once to ask for the bitrate variables, but it doesn't pause for info when utilizing the find command, but it does if I run the script directly.

Is there a way to combine the find command into the other script to make it a simple command that then prompts me for info? If not, what can I do to get it to prompt me?


Solution

  • The problem is that the shell script inherits its standard input from xargs, and its input is the pipe from find. So the script is trying to read from that pipe.

    If you can modify the script, change it to read the inputs from /dev/tty instead of standard input. Put this at the beginning of the script:

    exec </dev/tty