0

I'm trying to speed up some workflow by grouping a bunch of individual scripts we have to just get called in succession by a single shell script. The problem is one of the scripts I'm trying to call relies on a series of prompts and read statements to get input.

It's a very widely used script so I don't want to go monkeying around changing how it accepts input. Is there any way to feed it parameters in such a way that it will read them as "responses" to each prompt in the correct order?

lemmox
  • 1
  • 2
  • "Don't design your scripts that way" is really the better answer. That said, yes, you can feed input on stdin. – Charles Duffy Sep 18 '15 at 22:12
  • I wouldn't have had I written it, I can promise that. Sorry what do you mean, I'm fairly new to this. – lemmox Sep 18 '15 at 22:12
  • *nod*. At minimum, one can check for content being fed in on environment variables and prompt only if they're not set: `[[ $foo ]] || { printf '%s' "Enter value for foo: "; read foo; }` -- which gives you a route to make the script more easily programmably-invoked without changing its behavior for legacy users. – Charles Duffy Sep 18 '15 at 22:14
  • A special case of this is the `yes` utility: http://linux.die.net/man/1/yes – chucksmash Sep 18 '15 at 22:16

1 Answers1

0

Simply feed the content you want in on stdin. One easy way is to use a heredoc:

./secondscript <<EOF
$first_answer
$second_answer
...etc...
EOF

Assuming that the value of first_answer, second_answer, etc. are all one line each, they'll be fed to corresponding read calls inside the script so invoked.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441