While yes | child.sh
as manatwork already commented is a valid solution, from a programmers point of view I would patch child.sh
to be able to handle this usecase.
Like add an --force
option to not prompt but always overwrite files.
But to answer the subject of your question and to get something more expect
-like and not only fire y
via a pipe:
#!/bin/bash
fifo=fifo
mkfifo ${fifo}
exec 3<> ${fifo}
expect="Would you like to replace the configuration file with a new one? (Yes/No/Abort): "
answer="y"
while IFS= read -d $'\0' -n 1 a ; do
str+="${a}"
if [ "${str}" = "${expect}" ] ; then
echo "!!! found: ${str}"
echo ">>> sending answer: ${answer}"
echo "${answer}" >&3
unset str
fi
if [ "$a" = $'\n' ] ; then
echo -n "--- discarding input line: ${str}"
unset str
fi
done < <(./child.sh <${fifo})
rm ${fifo}
I just wrote that.. so it is not really failsafe or tested for solving specific problems..
So use at your own risk 8) Some line buffering problems may occur under some conditions..
But at least it worked in my test scenario..
echo y | child.sh
should do it. (If the question may occur multiple times, thenyes y | child.sh
.)... bla bla ... child.sh option
man yes
, read it