[英]Bash export and use variable with quotes and space in script
I'm trying to pass many jvm parameters to one variable and export it and call in other script, but space nad double quotes in parameter beat me.我试图将许多 jvm 参数传递给一个变量并将其导出并在其他脚本中调用,但参数中的空格和双引号击败了我。 ("/05 abcdef")
("/05 abcdef")
My code:我的代码:
#!/bin/bash
NORMAL_VARIABLE=-DNORMAL.NormalText=normal124
PROBLEMATIC_VARIABLE='-DPROBLEM.ProblematicText="/05 abcdef"'
SUM="$NORMAL_VARIABLE $PROBLEMATIC_VARIABLE"
export SUM
Target script:目标脚本:
java $SUM -jar "ApacheJMeter.jar" "$@"
Actual output in debug mode:调试模式下的实际输出:
+ NORMAL_VARIABLE=-DNORMAL.NormalText=normal124
+ PROBLEMATIC_VARIABLE='-DPROBLEM.ProblematicText="/05 abcdef"'
+ SUM='-DNORMAL.NormalText=normal124 -DPROBLEM.ProblematicText="/05 abcdef"'
+ export SUM
+ java -DNORMAL.NormalText=normal124 '-DPROBLEM.ProblematicText="/05' 'abcdef"' -jar ApacheJMeter.jar
Error: Could not find or load main class abcdef"
Anyone have an idea how to solve it?任何人都知道如何解决它?
I want to get:我想得到:
java -DNORMAL.NormalText=normal124 -DPROBLEM.ProblematicText="/05 abcdef" -jar ApacheJMeter.jar
If you're using bash, you can use arrays.如果您使用 bash,则可以使用数组。
#!/bin/bash
NORMAL_VARIABLE=-DNORMAL.NormalText=normal124
PROBLEMATIC_VARIABLE=-DPROBLEM.ProblematicText="/05 abcdef"
SUM=($NORMAL_VARIABLE "$PROBLEMATIC_VARIABLE")
And then进而
java "${SUM[@]}" -jar "ApacheJMeter.jar" "$@"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.