Issue with Command Line arguments which got spaces in it

前端 未结 5 1943
心在旅途
心在旅途 2020-11-29 09:41

I have a Java program which I\'m executing in a Linux environment through a bash script.

This is my simple bash script, which accepts a String.

#!/bi         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 10:18

    This is not a Java issue per se. It's a shell issue, and applies to anything you invoke with such arguments. Your shell is splitting up the arguments and feeding them separately to the Java process.

    You have to quote the arguments such that the shell doesn't split them up. e.g.

    $ java  -cp ... "Apple Inc. 2013"
    

    etc. See here for a longer discussion.

提交回复
热议问题