我正在編寫一個bash腳本以在內部Java應用程序服務器中啓動java類。但是,在下面的命令中,類名替換期間會出現一些(')。這使得啓動失敗,因爲mvn需要某種格式的命令。額外'在bash腳本中導致mvn失敗
#!/bin/bash -x
function launchClassInEngine {
CLASS_NAME=`echo \"launch-in-engine $1\"`
# echo as I would want it to "launch-in-engine MyClass"
echo ${CLASS_NAME}
# The problem starts here
# output: mvn '-Dclass="launch-in-engine' MyClass 'id=20"'
mvn -Dclass=\"launch-in-engine $1 $2\"
# so the problem is that while substituting the string at -Dclass= bash adds '
# I do not know how to fix this. Any idea or pointers
}
# Expect the below call to run
# mvn -Dclass="launch-in-engine MyClass id=20"
launchClassInEngine MyClass id=20
感謝您的幫助。
謝謝弗雷德。這有幫助。 – Kaps