Run parts of bash script : <p>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.</p>

<p>I have something that works, but it runs all part of the bash script yielding odd results.</p>

<p>Code:</p>

<pre><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
</code></pre>

<p>The results of the code: </p>

<p><a href="https://i.stack.imgur.com/B6olV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6olV.png" alt="Results"></a></p>

<p>Lines 5, 6, and 13 shouldn't run.</p>

<p>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.</p>
