The rd commands show errors like so:
==> rundeck: /etc/rundeck/profile: line 21: [: argument expected
Here is line 21
You might run shell scripts through shellcheck (http://shellcheck.net/) to find likely issues with accuracy and maintainability.
It's a lifesaver for code like this that should be written once, tested once, and then forgotten because it never needs to be changed in any significant way. :)
In addition, is the -n argument to test (a.k.a. [) available in a Bourne or POSIX shell? I always thought it was bash specific. It isn't noted as a problem by shellcheck, so I might be wrong.
Fix issue #2089 and some [shellcheck](http://shellcheck.net) warning
The script fails in a strange case: there is a defined JAVA_HOME, but no executable bin/java in it. Anyway it should not fail in such a way.
-n is one of the most low level test option, see: test specifications in posix.
But not -a, I will remove it. The recommendation from shellcheck about replacing 'for' using a ' | while read' loop is wrong because variable modification inside such a loop are done in a subshell, because of the |, and don't goes to the top level.
I have fixed that in #2091