Saving argument interval, etc. When going into mvn exec: java

I have a shell script that starts the Maven exec process: java -

exec mvn exec:java -Dexec.mainClass=... -Dexec.args="$*"

Now, unfortunately, if I ran

./myMagicShellScript arg1 "arg 2"

a single line arg 2does not execute it as a single argument, as we would like.

Any thoughts on how to escape / transfer things correctly (apparently in a clean way)?

+3
source share
1 answer

I took a look at the mvnscript and did some testing. Here is what I came up with:

Try changing your script to look like this:

args=(${@// /\\ })
exec mvn exec:java -Dexec.mainClass=... -Dexec.args="${args[*]}"

This changes all the spaces inside each element of the array using a backslash.

+5

Source: https://habr.com/ru/post/1761597/


All Articles