I have a bash script that employs the read
command to read arguments to commands interactively, for example yes/no options. Is there a way to call this script in a non-interactive script passing default option values as arguments?
It's not just one option that I have to pass to the interactive script.
Many ways
pipe your input
redirect from a file
use a here document (this can be very readable)
use a here string
For more complex tasks there is
expect
( http://en.wikipedia.org/wiki/Expect ). It basically simulates a user, you can code a script how to react to specific program outputs and related stuff.This also works in cases like
ssh
that prohibits piping passwords to it.Just want to add one more way. Found it elsewhere, and is quite simple. Say I want to pass yes for all the prompts at command line for a command "execute_command", Then I would simply pipe yes to it.
This will use yes as the answer to all yes/no prompts.
You can put the data in a file and re-direct it like this:
Data for the script:
Executing the script: