I have a script (that I cannot modify) that I must run regularly that has the following construct:
read -r response < /dev/tty
if [ "$response" = 'y' ]; then
...
I want to wrap this script such that I always send a "y" character to it. I've tried running the script with the standard tricks for sending a yes:
echo y | '/bin/bash /path/to/script'
and
yes | ./myscript
and
printf "y\n" | ./myscript
and
/bin/bash /path/to/script < /path/to/y-file
None of these work. I also tried expect
.
It's not clear if Mac OS X's built-in expect is working; with expect diagnostic information enabled, expect is properly detecting to the prompt and responding, but the script then terminates.
#!/bin/bash
set timeout -1
SCRIPT="~/myscript"
expect -d <<EOF
spawn $SCRIPT
expect "prompt string"
send "y\r"
EOF
Also, to clarify, this is on Mac OS X Monterey.
I'd appreciate any help. Again, I cannot modify the original script.