Reputation: 91
Hi I have a script which requires 4 yes inputs by the user while the 5th prompt requires a number.
Is there a way to stop yes command after 4 'yes' so that 5th prompt is free for user to enter a number.
Upvotes: 0
Views: 1854
Reputation: 58768
You can simply pass the required input instead:
printf '%s\n' 'yes' 'yes' 'yes' 'yes' '1234' | ./my_script.sh
PS: If it's your own script I would very much recommend making it non-interactive. ./my_script.sh --enable-foo --run-bar --do-baz --include-ban --repeat 1234
(or --foo
etc.) is longer but is enormously more expressive and therefore maintainable.
Upvotes: 5