A bash script was provided to me by a sysadmin which requires three values to be input by me. The values are read using "read" rather than read directly from the command-line.
echo "Enter value:"
read myValue
echo "Enter value 2:"
read myOtherValue
The three values I'd be entering are predictable, and I need to run this script frequently, so I would like to automate it; however, simply executing the script with the params in the command-line does not work.
./script.sh myValue myOtherValue
I can supply the first value if I echo it and then pipe it to the script, but that only works for the first param. I don't know how to pass the rest of them in this fashion.
echo "myValue" | ./script.sh
I do not have access to modify the script to just read the arguments.
Any ideas?
If the number of inputs is static you could use a here document:
If you are truely unable to copy this script to your home folder and make modifications to suit your needs, you should look into expect. Expect can read/write stdin/stdout to a program in an automated fashion.
This guide looks decent: http://www.ftlinuxcourse.com/FTLinuxCourse_Complete-2004/FTLinuxCourse/en/sysadm/chap5_3.html
Similar to Gerald Combs' answer, you can use process substitution and redirection:
or
or
or even:
Where, instead of two "echoes", you might have two different commands that produce the output you need for input to the script.