1

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?

2
  • Are you looking for read command? Commented Feb 17, 2014 at 3:46
  • Sort of the reverse. The script I'm trying to call is using the read command to take the user input and processing it accordingly. Commented Feb 17, 2014 at 3:49

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.