0

I have a simple requirement to be able to automate installing some other JDK on CentOS machine that already has its own JDK installed. As such here are the steps I execute on the CentOS node:

tar -zxvf jdk-8u221-linux-x64.tar.gz -C /usr
update-alternatives --install /usr/bin/java java /usr/jdk1.8.0_221/bin/java 2
alternatives --config java // and select 2 to proceed

Now under the final step I get the prompt and then have to manually enter 2. So all of that works fine. However, is there a way to skip the prompt and get that installed directly. The reason is because I am looking to automate this using a shell script.

Any help will be greatly appreciated.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Ashley
  • 1,447
  • 3
  • 26
  • 52
  • 1
    Does this answer your question? [Have bash script answer interactive prompts](https://stackoverflow.com/questions/3804577/have-bash-script-answer-interactive-prompts) – thanasisp Jun 02 '20 at 02:04
  • Thanks Mark. So i believe in my case it would be just 2 | alternatives --config java If so i will try that out because for my use case its always going to be entering 2 at the prompt after alternatives --config java – Ashley Jun 02 '20 at 14:20
  • I was able to solve this using simply alternatives --config java <<< '2' That did the trick for me – Ashley Jun 02 '20 at 16:55
  • 1
    Or we could also simply do echo -e "2" | alternatives --config java – Ashley Jun 02 '20 at 17:37

0 Answers0