0

I am running a jar file using a very basic shell script (I literally just need this to run on startup of a NAS). However, I am getting some rather unexpected behavior:

Script looks like this:

java -jar myJar.war --inputParam=10101 

myJar starts up - then throws a NumberFormatException saying that "10101 is not a valid number format. The question is: where is that " coming from? Anything I can try to avoid this behavior?

The exact same command works if I run it manually without a script since there's no " appearing.

Thank you kindly!

EDIT: hexdump of the original file:

0000000 / u s r / l o c a l / j r e / b 0000010 i n / j a v a - j a r / s h 0000020 a r e / m a t h u - g o / j e n 0000030 k i n s . w a r - - h t t p P 0000040 o r t = 1 0 1 0 1 \r \n 

Thanks for all the suggestions.

4
  • Maybe you can hack your way out of a bug by requesting java -jar myJar.war --inputParam=10101" instead (escaping the double quote character).
    – 41754
    CommentedAug 29, 2019 at 13:28
  • 2
    hexdump -C of the script file? maybe odd line endings or invisible characters sneaked their way inCommentedAug 29, 2019 at 13:28
  • Your file as a DOS text file. Try converting it to a Unix text file using dos2unix (or just retype it in a fresh file in a Unix text editor). The \r at the end of the line would be part of the argument passed to java.
    – Kusalananda
    CommentedAug 29, 2019 at 13:48
  • @Kusalananda recreating it seems to have worked. Thank you!CommentedAug 29, 2019 at 13:54

1 Answer 1

5

The issue is the carriage return at the end of the line in the script file (visible as \r in the output of hexdump -C). This is a DOS line-ending, but on Unix, the carriage return would be part of the argument to java.

The error message would have said "10101" (Java would quote the string that it had difficulties interpreting in the message), but since the carriage return returns the cursor to the start of the line while printing it, the last " would have been printed at the beginning of the line, which made the error message look a bit weird.

Retyping the script in a Unix text editor, or running dos2unix over the original file, would solve this.

Also note that a script should have a #!-line at the top. For example, inserting #!/bin/sh as the script's first line would make the the script run with /bin/sh as its interpreter.

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.