4

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."

....

2
  • 4
    Yes! linux.die.net/man/1/yes Commented Aug 4, 2014 at 7:21
  • To expand on @Ken's comment: yes | ./ittp-update.sh will answer yes to all questions (by entering yes followed by a newline over and over). Commented Aug 4, 2014 at 7:25

1 Answer 1

12

If you just need to answer "Yes" to everything, you can use

yes Yes | ./ittp-update.sh

How this works:

  1. The program 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.
  2. The pipe (|) connects standard output of the preceding command (yes) to the standard input of the following command (./ittp-update.sh).
  3. When ./ittp-update.sh finishes, the shell automatically sends SIGPIPE to any commands connected to it by pipes (only yes in this case).
  4. Upon receiving SIGPIPE, yes exits.

See man yes for more information.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.