Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I downloaded a program, and it came with a shell script to execute it since it was written in Java. I made a symlink to the shell script on my desktop. Then I edited the script (in its real location), adding cd $(dirname $(readlink $0)) to the top to make it follow the symbolic link back to the original script to get the directory right, because the script needs to access files in its directory (e.g., the jar file).

The modification works if I execute the symlink from bash with the ./symlink.sh command, but running it from my desktop environment causes it to say the main class could not be found, as if the cd never actually occurred.

Is there some difference between having your desktop environment execute it versus executing it directly in bash that would cause this? I'm running Cinnamon as my desktop.

Further examination of the script shows that it is using $(dirname "$0") to find the directory where it, and its associated files, are located.

share|improve this question

closed as unclear what you're asking by Gilles, cuonglm, Stephen Kitt, Anthon, taliezin Jun 10 at 15:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

    
Can you add a line echo $(dirname $(readlink $0)) > /tmp/dir-for-$$ to the script, run it in a shell and in the desktop environment, and tell us what the differences are in those two temp files? –  Mark Plotnick Jun 9 at 22:09
    
Please add set -x at the beginning of your script to see what is going on. –  michas Jun 9 at 22:10
    
@MarkPlotnick they both gave me the exact same path :/ –  Scoopta Jun 9 at 22:14
    
@michas is there anyway to get that to go into a file. Since the desktop environment is where the problem occurs I can't really see what's going on without pushing it to a file. –  Scoopta Jun 9 at 22:24
1  
This discussion is not really helpful until we see the actual code. Try to minimize the code you have (while still showing the problem) and add the result to your question. - Anything else is too much guessing. –  michas Jun 10 at 8:11

Browse other questions tagged or ask your own question.