Bob Shannon
Bob Shannon

Reputation: 648

Calling another shell script with bash and specifying input

I'm trying to call another shell script with bash, however this script doesn't accept any command line arguments. Instead, it runs, checks a few things, and then prompts the user for input like this:

Checking....done
Please enter ID #: (user input here)

Is it possible to do this?

Upvotes: 1

Views: 2141

Answers (3)

Nachiket Kate
Nachiket Kate

Reputation: 8571

If you have single input to feed then echo is enough like,

echo "input" | ./script.sh

if you have more than 1 input then expect is good and only option,

record a script as mentioned above and then run it

expect sampleexpect.expec

Upvotes: 0

Bob Shannon
Bob Shannon

Reputation: 648

The solution is to use expect.

#!/usr/bin/expect
spawn php /path/to/script
expect "ID #: "
send "{ID#}\r"
interact

Reference: Simulate user input in bash script

Upvotes: 2

Marcin Fabrykowski
Marcin Fabrykowski

Reputation: 619

Try something like this:

echo "My id" | ./script
Checking... done
Please enter ID: My id

or

./script << EOF
My_id
another input
EOF

Checking... done
Please enter ID: My_id
<blah>
Please enter something: anoter input

Upvotes: 2

Related Questions