Preserving argument spacing, etc when passing into mvn exec:java

纵饮孤独 提交于 2019-12-10 17:11:05

问题


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

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

Now sadly if I run

./myMagicShellScript arg1 "arg 2"

the single string arg 2 doesn't make it through as a single argument as I'd like.

Any thoughts as to how to escape / pass things through properly (perferably in a clean way)?


回答1:


I took a look at the mvn script and did some testing. This is what I came up with:

Try changing your script to look like this:

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

That changes all spaces which are within each array element to be escaped with a backslash.



来源:https://stackoverflow.com/questions/3570377/preserving-argument-spacing-etc-when-passing-into-mvn-execjava

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!