Content of /opt/scripts/jvm/jvm.script.sh#!/bin/bashJAVA_HOME='/java'PATH=$PATH:/$JAVA_HOME/binjava -cp ./classes:./lib com.mystuff.bar.foo.myclass &Content of /etc/init.d/init.script.shhome='/opt/scripts/jvm'program=jvm.script.shsu scriptuser -c $home/$program/opt/scripts/jvm is symlinked to /data/shellscripts (meaning /data/shellscripts exists as a real directory).Running the init script fails with cannot find class com.mystuff.bar.foo.myclassbut if I su to the same user and run it, it works, why?When I run su scriptuser -c 'declare -p JAVA_HOME' I get JAVA_HOME not found, but if I su to the user first (using su scriptuser) and run it, I get JAVA_HOME=/javaThis may sound crazy, but it seems to fix the issue if I add a trailing slash to the home variable in the init script.So:home='/opt/scripts/jvm'becomeshome='/opt/scripts/jvm/' It almost seems like something environmental is messing with the way the symlinks are being handled.
Bash script class path issue with java
bash;environment variables;java;su
It's a confusing question with the paths and su'ing.  When you run this command:$java -cp ./classes:./lib com.mystuff.bar.foo.myclassAnd get 'class not found', that means java is not able to find that class in ./classes or ./lib.  If you either a) use absolute paths, or b) cd to the right place before running the command (su scriptuser -c cd $home ; ./$program)it will work more reliably.As for why adding a / to home makes a difference, that does seem very strange.  You could break out strace/truss and see what system calls the command is making. This answer quotes from the posix spec:How linux handles multiple path separators (/home////username///file)and says For programs that act on a directory entry, if foo is a symbolic link to a directory, then passing foo/ is a way to make the program act on the directory instead of the symbolic link.