Issue with Command Line arguments which got spaces in it

前端 未结 5 1939
心在旅途
心在旅途 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:17

    In the original question the OP is using a shell script to call a java command line and would like the shell script to pass the arguments without performing the Blank interpretation (Word Splitting) option of input interpretation https://rg1-teaching.mpi-inf.mpg.de/unixffb-ss98/quoting-guide.html#para:sh-ifs

    If you know how many arguments there are then you can double quote the arguments

    #!/bin/bash
    java -cp  com.QuoteTester "$1"
    

    So you call this script, save as quotetester.sh.

    ./quotetester.sh "hello world" 
    

    and "hello world" gets passed as a single argument to Java. You could also use

    ./quotetester.sh hello\ world 
    

    with the same effect.

提交回复
热议问题