本文介绍了传递到 mvn exec:java 时保留参数间距等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 shell 脚本来启动一个 Maven exec:java 进程 -

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"

单个字符串 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)?

推荐答案

我看了一下mvn script 并做了一些测试.这是我想出的:

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.

这篇关于传递到 mvn exec:java 时保留参数间距等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 15:18