Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

./ 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" | ./

I do not have access to modify the script to just read the arguments.

Any ideas?

share|improve this question
up vote 2 down vote accepted

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:

share|improve this answer
Leave it to me to try to over-engineer a solution when the path of least resistance is right in front of me. Thanks! – Michael Moussa Oct 23 '09 at 15:07
Are you referring to making a copy, or using expect? :) – Kyle Smith Oct 23 '09 at 15:12

If the number of inputs is static you could use a here document:

cat <<FIN | ./
share|improve this answer
echo -e "MyValue\nMyOtherValue" | ./
share|improve this answer

Similar to Gerald Combs' answer, you can use process substitution and redirection:

./ < <(echo -e "myValue\nmyOtherValue")


./ < <(echo "myValue


./ < <(cat <<EOF

or even:

./ < <(echo "myValue"; echo "myOtherValue")

Where, instead of two "echoes", you might have two different commands that produce the output you need for input to the script.

share|improve this answer
Shouldn't the last one read ./ < <(echo "myValue"; echo "myOtherValue") ? – Kyle Smith Oct 23 '09 at 18:39
Thanks for the correction. – Dennis Williamson Oct 23 '09 at 19:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.