问题
Consider shell scripts which ask user's input to proceed or not[yY/nN] and
another script calls all these scripts.
I don't want to give Yy input manually.
Note: User input is not an argument to a script and it occurs anytime during script execution.
Consider 3 shell scripts viz: a.sh, b.sh, c.sh
.
On execution, scripts prompt:
"You want to Proceed[Y/y/N/n]?"
Now, Wrapper.sh
calls a.sh, b.sh, c.sh
and also provides Y/y or N/n input as and when those scripts prompts.
I can not pass an argument as a.sh "Y"
[ps: a.sh b.sh c.sh are not executable and non-editable]
Can not install any third party plugins on RHEL, So need to use only default plugins/commands.
回答1:
You can try expect
tool which is used to feed input automatically to an interactive program. Try to begin with something like this:
#!/usr/bin/expect
set timeout 10
spawn "PATH_TO/a.sh"
expect "You want to Proceed"
send "y\r"
interact
回答2:
I haven't used this myself, but take a look at 'expect'. This exactly what it's there for. Good luck!
来源:https://stackoverflow.com/questions/19954540/how-to-handle-user-prompt-user-intervention-during-shell-script-execution