I'm automating some things via bash and one of the things I wish to do is only execute a certain command if a condition is false.
I have written this little script to check the existence of java on a machine and then, if it doesn't exist, install java on the machine:
#!/bin/bash
java_path=$(which java)
if [ "$java_path" = "/usr/bin/java" ]; then
printf "\nJava Installed, version:\n"
java -version
else
printf "\nJava Not Installed, Installing...\n"
#sudo amazon-linux-extras install java-openjdk11
java -version
fi
My problem is that the code always goes down the else path, even though when I execute which java
via commandline, I get usr/bin/java
What am I doing wrong?