I've a weird issue coming on a new server that I switched (switched from ubuntu 18_04 to Red hat linux). One of our script started throwing an error, but if I copy paste the same command on command shell, it works fine.
Shell is bash and the command is
g++ -Wall -fPIC -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -shared -o Test.so Test.cpp
so it works fine if ran manually, but throws the following error while ran inside any script.
In file included from Test.cpp:2:
Test.h:2:10: fatal error: jni.h: No such file or directory
#include <jni.h>
^~~~~~~
compilation terminated.
I tried running script by all possible forms, removed all the other commands but this one and even this simplest script is throwing the same error that I posted above; test.sh
#!/bin/bash
g++ -Wall -fPIC -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -shared -o Test.so Test.cpp
So my question is that if a command runs without any issue on command prompt/bash, (where it does find all paths for JAVA_HOME, finds jni.h and generate the .so file) then why does it fail inside a script?