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?

Bob Shannon
  • 638
  • 2
  • 10
  • 19

3 Answers3

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
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

Community
  • 1
  • 1
Bob Shannon
  • 638
  • 2
  • 10
  • 19
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

Nachiket Kate
  • 8,473
  • 2
  • 27
  • 45