英文:
Jar file escapes "--" from substituted variable - Bash
问题
Code:
#!/bin/bash
MyVariable="--option arg1,arg2"
echo Variable output : $MyVariable
java -jar HelloInternet.jar "$MyVariable"
Expected results:
The jar file should recognize and use the value stored in the variable.
Actual results:
The jar file escapes "--" from "--option arg1,arg2", and interprets the variable without the "--".
Include any error messages:
Exception in thread "main" joptsimple.UnrecognizedOptionException: option arg1,arg2 is not a recognized option
Describe what you have tried:
I tried using ' '
instead of " "
and vice versa without success.
英文:
Code:
#!/bin/bash
MyVariable="--option arg1,arg2"
echo Variable output : $MyVariable
java -jar HelloInternet.jar "$MyVariable"
Expected results:
The jar file should recognize and use the value stored in variable.
Actual results:
The jar file escapes "--" from "--option arg1,arg2" , and interprets the variable without the "--" .
Include any error messages:
Exception in thread "main" joptsimple.UnrecognizedOptionException: option arg1,arg2 is not a recognized option
Describe what you have tried:
I tried using ' '
instead of " "
and vice versa without success.
答案1
得分: 0
使用数组当你需要一个数组:
MyVariable=(--option arg1,arg2)
java -jar HelloInternet.jar "${MyVariable[@]}"
英文:
Use an array when you need an array:
MyVariable=(--option arg1,arg2)
java -jar HelloInternet.jar "${MyVariable[@]}"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论