java -version In Bash Script. Giving integer error
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to make this if..fi
case work for the Java Version from wrapper.conf
configuration file./ and from the system, If the output from wrapper.conf
is java
I would have two options;
1. wrapper.java.command=/apps/jdk1.8.0_191/bin/java
2. wrapper.java.command=java
If it's long one with Java Version it should just print it.
If it's just java, which means it's using default java, and should check the java -version.
With Below script, I am failing to get it. I am getting below error.
integer expression expected
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
Script Snippet:
for file in $(echo $folder/conf/wrapper.conf)
do
JavaVersion=$(grep "command" $file | awk -F "=" 'print $NF')
if [ "$JavaVersion" -eq "java" ]; then
java -version 2>&1 >/dev/null | grep 'java version'
else
$JavaVersion
fi
linux scripting java test
add a comment |
up vote
0
down vote
favorite
I am trying to make this if..fi
case work for the Java Version from wrapper.conf
configuration file./ and from the system, If the output from wrapper.conf
is java
I would have two options;
1. wrapper.java.command=/apps/jdk1.8.0_191/bin/java
2. wrapper.java.command=java
If it's long one with Java Version it should just print it.
If it's just java, which means it's using default java, and should check the java -version.
With Below script, I am failing to get it. I am getting below error.
integer expression expected
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
Script Snippet:
for file in $(echo $folder/conf/wrapper.conf)
do
JavaVersion=$(grep "command" $file | awk -F "=" 'print $NF')
if [ "$JavaVersion" -eq "java" ]; then
java -version 2>&1 >/dev/null | grep 'java version'
else
$JavaVersion
fi
linux scripting java test
3
Welcome on U&L! It looks like a finaldone
is missing in your snippet.
– fra-san
Nov 28 at 16:21
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to make this if..fi
case work for the Java Version from wrapper.conf
configuration file./ and from the system, If the output from wrapper.conf
is java
I would have two options;
1. wrapper.java.command=/apps/jdk1.8.0_191/bin/java
2. wrapper.java.command=java
If it's long one with Java Version it should just print it.
If it's just java, which means it's using default java, and should check the java -version.
With Below script, I am failing to get it. I am getting below error.
integer expression expected
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
Script Snippet:
for file in $(echo $folder/conf/wrapper.conf)
do
JavaVersion=$(grep "command" $file | awk -F "=" 'print $NF')
if [ "$JavaVersion" -eq "java" ]; then
java -version 2>&1 >/dev/null | grep 'java version'
else
$JavaVersion
fi
linux scripting java test
I am trying to make this if..fi
case work for the Java Version from wrapper.conf
configuration file./ and from the system, If the output from wrapper.conf
is java
I would have two options;
1. wrapper.java.command=/apps/jdk1.8.0_191/bin/java
2. wrapper.java.command=java
If it's long one with Java Version it should just print it.
If it's just java, which means it's using default java, and should check the java -version.
With Below script, I am failing to get it. I am getting below error.
integer expression expected
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
Script Snippet:
for file in $(echo $folder/conf/wrapper.conf)
do
JavaVersion=$(grep "command" $file | awk -F "=" 'print $NF')
if [ "$JavaVersion" -eq "java" ]; then
java -version 2>&1 >/dev/null | grep 'java version'
else
$JavaVersion
fi
linux scripting java test
linux scripting java test
edited Nov 28 at 21:28
asked Nov 28 at 16:00
Bek
63
63
3
Welcome on U&L! It looks like a finaldone
is missing in your snippet.
– fra-san
Nov 28 at 16:21
add a comment |
3
Welcome on U&L! It looks like a finaldone
is missing in your snippet.
– fra-san
Nov 28 at 16:21
3
3
Welcome on U&L! It looks like a final
done
is missing in your snippet.– fra-san
Nov 28 at 16:21
Welcome on U&L! It looks like a final
done
is missing in your snippet.– fra-san
Nov 28 at 16:21
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
Besides the missing done
for your loop that fra-san commented on and the -eq
integer comparison complaining about the strings you asked it to compare, there's also the error where you called some particular java binary with no parameters, generating the second half of the error you saw.
Since you're likely wanting the java version in either case, simply execute $JavaVersion
regardless.
JavaVersion=$(grep wrapper.java.command= "$file" | awk -F "=" 'print $NF')
"$JavaVersion" -version
Appears I misunderstood the end goal of printing the wrapper.java.command value if it's not exactly java
, otherwise executing java -version
.
if grep -Fxq wrapper.java.command=java "$file"
then
java -version 2>&1 | grep 'java version'
else
grep ^wrapper.java.command= "$file" | cut -d= -f2-
fi
Hey Jeff Schaller, Thank you for the Answer. I have the other "done" at the end of the script. Since it's big script, I just took one snipped from it. Can you please explain what this will do here? "$JavaVersion" -version
– Bek
Nov 28 at 16:56
It'll run whatever you found in the file as the wrapper.java.command and add the-version
option.I put quotes around it in case someone decided to package a "/usr/bin/java funny version with spaces"
– Jeff Schaller
Nov 28 at 16:58
I need to run java -version and get the Default Java Version from the system. What would be best way to get it?
– Bek
Nov 28 at 17:10
1
runjava -version
? I'm not sure what "Default Java Version" is in this situation. Perhaps it's worth a separate question?
– Jeff Schaller
Nov 28 at 17:33
Actually this is my Main Concern here :) I need to get java -version from the system, if the output from wrapper.conf is "java" if long text, then just print.
– Bek
Nov 28 at 19:44
|
show 3 more comments
up vote
2
down vote
The -eq
operator is for integer comparison. Since you are trying to compare strings you will need to use =
, specifically:
if [ "$JavaVersion" = "java" ]; then
Additionally, the following line seems flawed:
java -version 2>&1 >/dev/null | grep 'java version'
You are redirecting both stdout and stderr to /dev/null (all output) so there will be nothing left to grep.
Thank you for your input. I have modified "-eq" to "=" operator. Regarding the Java Command, I can get the output on the command line. What do you suggest me to replace it with?
– Bek
Nov 28 at 16:50
@Bek I suggest removing the redirects. So just:java -version | grep 'java version'
– Jesse_b
Nov 28 at 16:52
java -version |grep 'java version' is giving me every single text it has. I can't even filter it with awk. Have you tested it? Not working for me thou.
– Bek
Nov 28 at 16:58
I have tested with - java -version | grep 'java version' - And still giving the same Integer error
– Bek
Nov 28 at 17:03
2
java -version
outputs the text to stderr
– Jeff Schaller
Nov 28 at 17:33
|
show 2 more comments
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Besides the missing done
for your loop that fra-san commented on and the -eq
integer comparison complaining about the strings you asked it to compare, there's also the error where you called some particular java binary with no parameters, generating the second half of the error you saw.
Since you're likely wanting the java version in either case, simply execute $JavaVersion
regardless.
JavaVersion=$(grep wrapper.java.command= "$file" | awk -F "=" 'print $NF')
"$JavaVersion" -version
Appears I misunderstood the end goal of printing the wrapper.java.command value if it's not exactly java
, otherwise executing java -version
.
if grep -Fxq wrapper.java.command=java "$file"
then
java -version 2>&1 | grep 'java version'
else
grep ^wrapper.java.command= "$file" | cut -d= -f2-
fi
Hey Jeff Schaller, Thank you for the Answer. I have the other "done" at the end of the script. Since it's big script, I just took one snipped from it. Can you please explain what this will do here? "$JavaVersion" -version
– Bek
Nov 28 at 16:56
It'll run whatever you found in the file as the wrapper.java.command and add the-version
option.I put quotes around it in case someone decided to package a "/usr/bin/java funny version with spaces"
– Jeff Schaller
Nov 28 at 16:58
I need to run java -version and get the Default Java Version from the system. What would be best way to get it?
– Bek
Nov 28 at 17:10
1
runjava -version
? I'm not sure what "Default Java Version" is in this situation. Perhaps it's worth a separate question?
– Jeff Schaller
Nov 28 at 17:33
Actually this is my Main Concern here :) I need to get java -version from the system, if the output from wrapper.conf is "java" if long text, then just print.
– Bek
Nov 28 at 19:44
|
show 3 more comments
up vote
3
down vote
Besides the missing done
for your loop that fra-san commented on and the -eq
integer comparison complaining about the strings you asked it to compare, there's also the error where you called some particular java binary with no parameters, generating the second half of the error you saw.
Since you're likely wanting the java version in either case, simply execute $JavaVersion
regardless.
JavaVersion=$(grep wrapper.java.command= "$file" | awk -F "=" 'print $NF')
"$JavaVersion" -version
Appears I misunderstood the end goal of printing the wrapper.java.command value if it's not exactly java
, otherwise executing java -version
.
if grep -Fxq wrapper.java.command=java "$file"
then
java -version 2>&1 | grep 'java version'
else
grep ^wrapper.java.command= "$file" | cut -d= -f2-
fi
Hey Jeff Schaller, Thank you for the Answer. I have the other "done" at the end of the script. Since it's big script, I just took one snipped from it. Can you please explain what this will do here? "$JavaVersion" -version
– Bek
Nov 28 at 16:56
It'll run whatever you found in the file as the wrapper.java.command and add the-version
option.I put quotes around it in case someone decided to package a "/usr/bin/java funny version with spaces"
– Jeff Schaller
Nov 28 at 16:58
I need to run java -version and get the Default Java Version from the system. What would be best way to get it?
– Bek
Nov 28 at 17:10
1
runjava -version
? I'm not sure what "Default Java Version" is in this situation. Perhaps it's worth a separate question?
– Jeff Schaller
Nov 28 at 17:33
Actually this is my Main Concern here :) I need to get java -version from the system, if the output from wrapper.conf is "java" if long text, then just print.
– Bek
Nov 28 at 19:44
|
show 3 more comments
up vote
3
down vote
up vote
3
down vote
Besides the missing done
for your loop that fra-san commented on and the -eq
integer comparison complaining about the strings you asked it to compare, there's also the error where you called some particular java binary with no parameters, generating the second half of the error you saw.
Since you're likely wanting the java version in either case, simply execute $JavaVersion
regardless.
JavaVersion=$(grep wrapper.java.command= "$file" | awk -F "=" 'print $NF')
"$JavaVersion" -version
Appears I misunderstood the end goal of printing the wrapper.java.command value if it's not exactly java
, otherwise executing java -version
.
if grep -Fxq wrapper.java.command=java "$file"
then
java -version 2>&1 | grep 'java version'
else
grep ^wrapper.java.command= "$file" | cut -d= -f2-
fi
Besides the missing done
for your loop that fra-san commented on and the -eq
integer comparison complaining about the strings you asked it to compare, there's also the error where you called some particular java binary with no parameters, generating the second half of the error you saw.
Since you're likely wanting the java version in either case, simply execute $JavaVersion
regardless.
JavaVersion=$(grep wrapper.java.command= "$file" | awk -F "=" 'print $NF')
"$JavaVersion" -version
Appears I misunderstood the end goal of printing the wrapper.java.command value if it's not exactly java
, otherwise executing java -version
.
if grep -Fxq wrapper.java.command=java "$file"
then
java -version 2>&1 | grep 'java version'
else
grep ^wrapper.java.command= "$file" | cut -d= -f2-
fi
edited Nov 28 at 22:44
answered Nov 28 at 16:26
Jeff Schaller
37.2k1052121
37.2k1052121
Hey Jeff Schaller, Thank you for the Answer. I have the other "done" at the end of the script. Since it's big script, I just took one snipped from it. Can you please explain what this will do here? "$JavaVersion" -version
– Bek
Nov 28 at 16:56
It'll run whatever you found in the file as the wrapper.java.command and add the-version
option.I put quotes around it in case someone decided to package a "/usr/bin/java funny version with spaces"
– Jeff Schaller
Nov 28 at 16:58
I need to run java -version and get the Default Java Version from the system. What would be best way to get it?
– Bek
Nov 28 at 17:10
1
runjava -version
? I'm not sure what "Default Java Version" is in this situation. Perhaps it's worth a separate question?
– Jeff Schaller
Nov 28 at 17:33
Actually this is my Main Concern here :) I need to get java -version from the system, if the output from wrapper.conf is "java" if long text, then just print.
– Bek
Nov 28 at 19:44
|
show 3 more comments
Hey Jeff Schaller, Thank you for the Answer. I have the other "done" at the end of the script. Since it's big script, I just took one snipped from it. Can you please explain what this will do here? "$JavaVersion" -version
– Bek
Nov 28 at 16:56
It'll run whatever you found in the file as the wrapper.java.command and add the-version
option.I put quotes around it in case someone decided to package a "/usr/bin/java funny version with spaces"
– Jeff Schaller
Nov 28 at 16:58
I need to run java -version and get the Default Java Version from the system. What would be best way to get it?
– Bek
Nov 28 at 17:10
1
runjava -version
? I'm not sure what "Default Java Version" is in this situation. Perhaps it's worth a separate question?
– Jeff Schaller
Nov 28 at 17:33
Actually this is my Main Concern here :) I need to get java -version from the system, if the output from wrapper.conf is "java" if long text, then just print.
– Bek
Nov 28 at 19:44
Hey Jeff Schaller, Thank you for the Answer. I have the other "done" at the end of the script. Since it's big script, I just took one snipped from it. Can you please explain what this will do here? "$JavaVersion" -version
– Bek
Nov 28 at 16:56
Hey Jeff Schaller, Thank you for the Answer. I have the other "done" at the end of the script. Since it's big script, I just took one snipped from it. Can you please explain what this will do here? "$JavaVersion" -version
– Bek
Nov 28 at 16:56
It'll run whatever you found in the file as the wrapper.java.command and add the
-version
option.I put quotes around it in case someone decided to package a "/usr/bin/java funny version with spaces"– Jeff Schaller
Nov 28 at 16:58
It'll run whatever you found in the file as the wrapper.java.command and add the
-version
option.I put quotes around it in case someone decided to package a "/usr/bin/java funny version with spaces"– Jeff Schaller
Nov 28 at 16:58
I need to run java -version and get the Default Java Version from the system. What would be best way to get it?
– Bek
Nov 28 at 17:10
I need to run java -version and get the Default Java Version from the system. What would be best way to get it?
– Bek
Nov 28 at 17:10
1
1
run
java -version
? I'm not sure what "Default Java Version" is in this situation. Perhaps it's worth a separate question?– Jeff Schaller
Nov 28 at 17:33
run
java -version
? I'm not sure what "Default Java Version" is in this situation. Perhaps it's worth a separate question?– Jeff Schaller
Nov 28 at 17:33
Actually this is my Main Concern here :) I need to get java -version from the system, if the output from wrapper.conf is "java" if long text, then just print.
– Bek
Nov 28 at 19:44
Actually this is my Main Concern here :) I need to get java -version from the system, if the output from wrapper.conf is "java" if long text, then just print.
– Bek
Nov 28 at 19:44
|
show 3 more comments
up vote
2
down vote
The -eq
operator is for integer comparison. Since you are trying to compare strings you will need to use =
, specifically:
if [ "$JavaVersion" = "java" ]; then
Additionally, the following line seems flawed:
java -version 2>&1 >/dev/null | grep 'java version'
You are redirecting both stdout and stderr to /dev/null (all output) so there will be nothing left to grep.
Thank you for your input. I have modified "-eq" to "=" operator. Regarding the Java Command, I can get the output on the command line. What do you suggest me to replace it with?
– Bek
Nov 28 at 16:50
@Bek I suggest removing the redirects. So just:java -version | grep 'java version'
– Jesse_b
Nov 28 at 16:52
java -version |grep 'java version' is giving me every single text it has. I can't even filter it with awk. Have you tested it? Not working for me thou.
– Bek
Nov 28 at 16:58
I have tested with - java -version | grep 'java version' - And still giving the same Integer error
– Bek
Nov 28 at 17:03
2
java -version
outputs the text to stderr
– Jeff Schaller
Nov 28 at 17:33
|
show 2 more comments
up vote
2
down vote
The -eq
operator is for integer comparison. Since you are trying to compare strings you will need to use =
, specifically:
if [ "$JavaVersion" = "java" ]; then
Additionally, the following line seems flawed:
java -version 2>&1 >/dev/null | grep 'java version'
You are redirecting both stdout and stderr to /dev/null (all output) so there will be nothing left to grep.
Thank you for your input. I have modified "-eq" to "=" operator. Regarding the Java Command, I can get the output on the command line. What do you suggest me to replace it with?
– Bek
Nov 28 at 16:50
@Bek I suggest removing the redirects. So just:java -version | grep 'java version'
– Jesse_b
Nov 28 at 16:52
java -version |grep 'java version' is giving me every single text it has. I can't even filter it with awk. Have you tested it? Not working for me thou.
– Bek
Nov 28 at 16:58
I have tested with - java -version | grep 'java version' - And still giving the same Integer error
– Bek
Nov 28 at 17:03
2
java -version
outputs the text to stderr
– Jeff Schaller
Nov 28 at 17:33
|
show 2 more comments
up vote
2
down vote
up vote
2
down vote
The -eq
operator is for integer comparison. Since you are trying to compare strings you will need to use =
, specifically:
if [ "$JavaVersion" = "java" ]; then
Additionally, the following line seems flawed:
java -version 2>&1 >/dev/null | grep 'java version'
You are redirecting both stdout and stderr to /dev/null (all output) so there will be nothing left to grep.
The -eq
operator is for integer comparison. Since you are trying to compare strings you will need to use =
, specifically:
if [ "$JavaVersion" = "java" ]; then
Additionally, the following line seems flawed:
java -version 2>&1 >/dev/null | grep 'java version'
You are redirecting both stdout and stderr to /dev/null (all output) so there will be nothing left to grep.
edited Nov 28 at 16:28
answered Nov 28 at 16:20
Jesse_b
11.5k23063
11.5k23063
Thank you for your input. I have modified "-eq" to "=" operator. Regarding the Java Command, I can get the output on the command line. What do you suggest me to replace it with?
– Bek
Nov 28 at 16:50
@Bek I suggest removing the redirects. So just:java -version | grep 'java version'
– Jesse_b
Nov 28 at 16:52
java -version |grep 'java version' is giving me every single text it has. I can't even filter it with awk. Have you tested it? Not working for me thou.
– Bek
Nov 28 at 16:58
I have tested with - java -version | grep 'java version' - And still giving the same Integer error
– Bek
Nov 28 at 17:03
2
java -version
outputs the text to stderr
– Jeff Schaller
Nov 28 at 17:33
|
show 2 more comments
Thank you for your input. I have modified "-eq" to "=" operator. Regarding the Java Command, I can get the output on the command line. What do you suggest me to replace it with?
– Bek
Nov 28 at 16:50
@Bek I suggest removing the redirects. So just:java -version | grep 'java version'
– Jesse_b
Nov 28 at 16:52
java -version |grep 'java version' is giving me every single text it has. I can't even filter it with awk. Have you tested it? Not working for me thou.
– Bek
Nov 28 at 16:58
I have tested with - java -version | grep 'java version' - And still giving the same Integer error
– Bek
Nov 28 at 17:03
2
java -version
outputs the text to stderr
– Jeff Schaller
Nov 28 at 17:33
Thank you for your input. I have modified "-eq" to "=" operator. Regarding the Java Command, I can get the output on the command line. What do you suggest me to replace it with?
– Bek
Nov 28 at 16:50
Thank you for your input. I have modified "-eq" to "=" operator. Regarding the Java Command, I can get the output on the command line. What do you suggest me to replace it with?
– Bek
Nov 28 at 16:50
@Bek I suggest removing the redirects. So just:
java -version | grep 'java version'
– Jesse_b
Nov 28 at 16:52
@Bek I suggest removing the redirects. So just:
java -version | grep 'java version'
– Jesse_b
Nov 28 at 16:52
java -version |grep 'java version' is giving me every single text it has. I can't even filter it with awk. Have you tested it? Not working for me thou.
– Bek
Nov 28 at 16:58
java -version |grep 'java version' is giving me every single text it has. I can't even filter it with awk. Have you tested it? Not working for me thou.
– Bek
Nov 28 at 16:58
I have tested with - java -version | grep 'java version' - And still giving the same Integer error
– Bek
Nov 28 at 17:03
I have tested with - java -version | grep 'java version' - And still giving the same Integer error
– Bek
Nov 28 at 17:03
2
2
java -version
outputs the text to stderr– Jeff Schaller
Nov 28 at 17:33
java -version
outputs the text to stderr– Jeff Schaller
Nov 28 at 17:33
|
show 2 more comments
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484702%2fjava-version-in-bash-script-giving-integer-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Welcome on U&L! It looks like a final
done
is missing in your snippet.– fra-san
Nov 28 at 16:21