0

i've the following problem, these is my shell script:

#!/bin/bash
CONFIG_FOLDER=./config
JAVA_HOME=/home/lorenzo/Downloads/jdk1.7.0_25/bin
CHARSET=utf8
$JAVA_HOME/java -DconfigFolder=$CONFIG_FOLDER -jar com.lorenzo.myapp.jar 

When I run the script I get the following error:

/java: not foundmyscript.sh: 5: myscritp.sh: /home/lorenzo/Downloads/jdk1.7.0_25/bin

Any idea?

P.S myscript.sh is the posted script.

EDIT:

I've found a partial solution:

#!/bin/bash
CONFIG_FOLDER=./config
export PATH=$PATH:/home/user/jdk1.7/bin
java -DconfigFolder=$CONFIG_FOLDER -jar com.lorenzo.myapp.jar 

But now, I've another problem: the value of $CONFIG_FOLDER is empty when i run the script. Why?

antlion
  • 1
  • 3
  • Did you try changing the order between `-D` and `-jar`? Like this: `$JAVA_HOME/java -jar -DconfigFolder=$CONFIG_FOLDER com.lorenzo.myapp.jar` – dic19 Aug 05 '13 at 14:08
  • I've tried now and nothing, same error...thanks for advice! – antlion Aug 05 '13 at 14:12
  • You're wellcome. Another question: What is `myscript.sh`? I mean is the sript you posted above or is another one contained in `./config` folder? – dic19 Aug 05 '13 at 14:28
  • Thank you! myscript.sh is the script that I've posted. – antlion Aug 05 '13 at 14:51
  • 1
    Then if I don't misunderstand the error is line 5 of `myscript.sh` due `sh` can't find (or solve) `/home/lorenzo/Downloads/jdk1.7.0_25/bin` (your `JAVA_HOME`). Make sure the path is right due I think it's not a java error but a `sh` error. – dic19 Aug 05 '13 at 15:00
  • Yes, but i the path is right! if I put instead of "$JAVA_HOME/java" the path /home/lorenzo/Downloads/jdk1.7.0_25/bin/java -DconfigFolder..the sh work well. Thank you for reply! – antlion Aug 06 '13 at 06:41
  • I see. What if you set `JAVA_HOME=/home/lorenzo/Downloads/jdk1.7.0_25/bin/java` (full path to java executable) and make the last line `$JAVA_HOME -jar -DconfigFolder=$CONFIG_FOLDER com.lorenzo.myapp.jar`? I still thinking there's something avoiding `sh` to solve `$JAVA_HOME` variable at last line, based in the fact if you put full path instead a variable your script actually works. – dic19 Aug 06 '13 at 11:15
  • Same error : /java: not foundmyscript.sh: 5: myscritp.sh: /home/lorenzo/Downloads/jdk1.7.0_25/bin/java – antlion Aug 07 '13 at 06:49
  • Well I don't know what else I can say. The error is clearly `sh` can't find `/java` in your `JAVA_HOME` but if you put exactly the same full path it actually works. What about change the approach? You can install java and just call `java -jar -DconfigFolder=$CONFIG_FOLDER` in your script. Your OS should be able to solve java path by itself. – dic19 Aug 07 '13 at 14:48
  • In my context, I can't install Java into linux. My business rules imposed on me to specify the path of java home in my shell scrpit. Anyhow thank very much @dic19 for your help! – antlion Aug 08 '13 at 07:59
  • Hi there! I hope you have solved your problem. But if you haven't [here](http://stackoverflow.com/questions/17927044/passing-java-command-line-arguments-in-a-shell-script) is a question about passing arguments in a shell script. I've seen when they use a variable they put it into brackets like `${JAVA_HOME}`. I've tried on my Linux Mint a script with and without brackets and I made work both but maybe your distro is different. – dic19 Aug 09 '13 at 13:52
  • @dic19 I've just tried with your solution, bu without result! – antlion Aug 10 '13 at 08:23

1 Answers1

0

Finally i've found solution! I wrote the script under Windows operative system. If i I open the script under Linux with vim text editor the script appear in this way:

#!/bin/bash^M
CONFIG_FOLDER=./config^M
JAVA_HOME=/home/lorenzo/Downloads/jdk1.7.0_25/bin^M
CHARSET=utf8^M
$JAVA_HOME/java -DconfigFolder=$CONFIG_FOLDER -jar com.lorenzo.myapp.jar^M

The script is dirty! After deleted all ^M the script worked!

antlion
  • 1
  • 3
  • I'm happy you have solved your problem :D But just curious, what is supossed to `^M` mean? Is the first time I see it but it's an oportunity to learn something new. – dic19 Aug 10 '13 at 11:45
  • Stack overflow is the way! http://stackoverflow.com/questions/64749/m-character-at-end-of-lines ahahahah – antlion Aug 12 '13 at 07:05