It seems as if today is not my day. First, I wrote a message in another thread 
with tons of typos, making it look as if I am not just bad in typing but 
actually unable to speak proper English. Now, I sent an incomplete message not 
addressing the actual question. Sorry for that to everyone.

Let us settle on only using double quotes to enclose arguments containing 
spaces. Then, we do not need to escape single quotes and can use them 
literally. But we do need to escape nested double quotes.

In UNIX-like shells like Bash, a double quote is escaped by a backslash:

  -Dexec.args="one \"it's OK\" three"

In Windows Cmd.exe, a double quote is escaped by another double quote:

  -Dexec.args="one ""it's OK"" three"

HTH
-- 
Alexander Kriegisch
https://scrum-master.de


Alexander Kriegisch schrieb am 15.10.2023 11:17 (GMT +07:00):

> Java CLI program arguments containing spaces are usually enclosed by
> double quotes, so I would recommend to use:
> 
>   -Dexec.args="one 'number two' three"
> 
> This works in both UNIX-like shells (say, Git Bash on Windows) and in the
> Cmd.exe Windows shell, while
> 
>   -Dexec.args='one "number two" three'
> 
> only works in UNIX-like shells, but *not* in Cmd.exe.
> 
> -- 
> Alexander Kriegisch
> https://scrum-master.de
> 
> 
> Garret Wilson schrieb am 15.10.2023 05:31 (GMT +07:00):
> 
>> Here's a fun one for your weekend. As you know from (almost) the 
>> beginning of time we could invoke a Java application using Maven using 
>> the Maven Exec Plugin, as in the following (although Maven's `--quiet` 
>> may be a recent addition):
>> 
>> ```bash
>> mvn exec:java -Dexec.mainClass="com.example.MyApplication" 
>> -Dexec.args="test" --quiet
>> ```
>> 
>> This passes a single command-line argument to my Java `main()` method 
>> args array: "test". If I want to pass a string with a space, I put it in 
>> single quotes, like this:
>> 
>> ```bash
>> mvn exec:java -Dexec.mainClass="com.example.MyApplication" 
>> -Dexec.args="'foo bar'" --quiet
>> ```
>> 
>> That passes a single string "foo bar" to my application `main()` method 
>> args array.
>> 
>> Now … what if I want to pass a single string "foo'bar" (note just one 
>> single quote in the string) as a single string to my `main()` method 
>> args array? is there some way to escape the single quote? The 
>> [documention](https://www.mojohaus.org/exec-maven-plugin/java-mojo.html#commandlineArgs)
>> 
>> doesn't give any clues.
>> 
>> I guess I could look at the Exec Maven Plugin source code (if it's 
>> available), but that would take half a day and I've already spent half 
>> of today going down other rabbit holes. So I thought I'd ask here to see 
>> if anyone knew; otherwise I'll investigate another day when I'm 
>> refreshed (or just put a temporary note in my Bash script about this 
>> corner case, but that's not really my style).
>> 
>> Garret
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
>> For additional commands, e-mail: users-h...@maven.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
> For additional commands, e-mail: users-h...@maven.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to