Reputation: 4037
There is a shell script it asks yes/no
multiple times almost 100 times when I run twice on a server. I'm tired of typing yes
every time. Is there any way to Run that script just taking yes as a default option.Assume following is my script! FYI, I can not edit my script.
Just I can run it using ./ittp-update.sh
#!/bin/bash
echo "Do you need to install the necessary compiling tools?"
select yn in "Yes" "No"; do
case $yn in
Yes ) sudo apt-get install tools; break;;
No ) <Here I want to skip to the next step. I originally left it
blank and removed the "done" command (after esac command)
to do this, but if I choose yes, it skips to the end
(where the next "done" command is and ends the script>
esac
echo "Do you need to eidt your configuration?"
select ny in "No" "Yes"; do
case $ny in
No ) <what do I put here to skip to the next tag
(labeled compile for example purposes); break;;
Yes )
esac
echo "You have 3 options with how you can edit you config file."
....
Upvotes: 4
Views: 7771
Reputation: 58768
If you just need to answer "Yes" to everything, you can use
yes Yes | ./ittp-update.sh
How this works:
yes
prints the string you give it (or "y" if you don't give it anything, since this is the default way to give a positive answer in *nix programs) repeatedly on standard output until it receives SIGPIPE
.|
) connects standard output of the preceding command (yes
) to the standard input of the following command (./ittp-update.sh
)../ittp-update.sh
finishes, the shell automatically sends SIGPIPE
to any commands connected to it by pipes (only yes
in this case).SIGPIPE
, yes
exits.See man yes
for more information.
Upvotes: 12