Bypass Yes / No in Shell Script

There is a shell script that asks for yes/no

multiple times almost 100 times when I run twice on the server. I'm tired of typing yes

every time. Is there a way to run this script just by selecting yes as the default option. Follow my script! FYI, I cannot change my script. I just can start it with./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."

      

....

+3


source to share


1 answer


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

yes Yes | ./ittp-update.sh

      

How it works:



  • The program yes

    prints the line you give it (or "y" if you don't give anything, since this is the standard way of giving a positive answer in * nix programs) repeatedly on standard output while it receives SIGPIPE

    .
  • A pipe ( |

    ) connects the standard output of the previous command ( yes

    ) to the standard input of the next command ( ./ittp-update.sh

    ).
  • When ./ittp-update.sh

    finished, the shell automatically dispatches SIGPIPE

    to any commands piped to it (only yes

    in this case).
  • SIGPIPE

    Completes when received yes

    .

For details see man yes

.

+5


source







All Articles