So I want to have an automated Bash script that checks for java and if its not there or super old version (lower than 7) it installs it.
I have something that works, but it runs all part of the bash script yielding odd results.
Code:
#!/bin/bash
# This file will call versions and install if necessary
version_call_java = $(java -version)
java_call_len = ${#version_call_java}
if [[ $version_call_java == *"not found"* ]]; then
echo "It's not there!"
sudo apt-get install java
echo "Installing Java"
elif [[ $version_call_java == *"version*" ]]
echo "Its there!"
fi
date
The results of the code:
Lines 5, 6, and 13 shouldn't run.
Also is my logic correct? I look for the words "not found" for if the machine doesn't have java. Maybe "recognized" is better but not sure if there is a boolean for if a software program exists or not on a machine.