Shell Script:
#!/bin/sh
# -*-sh-*-
java -classpath Test.jar Test test1.xml > javaOutput 2>&1;
if cat javaOutput | tr '\n' ' ' | grep ".*java.lang.IndexOutOfBoundsException0.*ArrayList.java:653.*Test.java:142.*" &>/dev/null; then
echo TRUE;
else
echo FALSE;
fi
Output File Content (javaOutput):
0,2,468.000000
1,2,305.000000
2,5,2702.000000
3,3,1672.000000
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at Test.processPayments(Test.java:113)
at Test.processFile(Test.java:131)
at Test.main(Test.java:142)
I am using the following version of ubuntu:
Distributor ID: Ubuntu
Description: Ubuntu 17.04
Release: 17.04
When I copy and paste the script in the command prompt it works fine and echos FALSE as expected but whenever I am executing the script it keeps echoing TRUE. I even ran this script in mac os and it executes as expected in MacOs. I am very puzzled. Any help or insight would be appreciated.
Note: The expectation here is to get FALSE since there is no string IndexOutOfBoundsException0 in the output content.
&>/dev/nullfrom the script, what does it print? Also, recent versions of Ubuntu use dash as /bin/sh (instead of the more common bash). I can't see anything dash would treat differently than bash, but try setting the shebang to#!/bin/bashand see if switches behavior.