0

When I tried to pass some program arguments from shell script to java program, the escape characters are not working.
Here is the code and command I tried to use.
Shell Script:

#!/usr/bin/bash
filename="DX.jar"
uid="111,110"

onCallName1="Tom"
onCallName2="Jerry"
onCallName3="Brun"

text="These are people who are on call: @$onCallName1, @$onCallName2 and @$onCallName3. \\n'
Please focus on the cases of online problems. \\n'
Safe cases monitor: https://a.b.com/page/992645614 \\n'
Old cases log: https://a.b.com/page/1012464399 \\n'
Cases feedback: https://a.b.com/page/1041338613"


# run!
java -jar $filename -uid $uid -text $text

The argument text should be parsed in the Java program and output itself like follows:

These are people who are on call: @$onCallName1, @$onCallName2 and @$onCallName3. Please focus on the cases of online problems. Safe cases monitor: https://km.sankuai.com/page/992645614 Old cases log: https://km.sankuai.com/page/1012464399 Cases feedback: https://km.sankuai.com/page/1041338613

But when I run this shell script like bash a.sh, it only outputs these:

These

Could anyone help me and give me some advice?
Thanks in advances.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
Bowen Peng
  • 1,635
  • 4
  • 21
  • 39
  • The last line of the script probably should contain `"$text"` instead of just `$text`. – VGR Aug 03 '21 at 12:11

1 Answers1

1

Try rewriting your script as follow and please tell if it works or not for you too:

#!/usr/bin/bash
filename="DX.jar"
uid="111,110"

onCallName1="Tom"
onCallName2="Jerry"
onCallName3="Brun"

text="These are people who are on call: @$onCallName1, @$onCallName2 and @$onCallName3. \n'
Please focus on the cases of online problems. \n'
Safe cases monitor: https://a.b.com/page/992645614 \n'
Old cases log: https://a.b.com/page/1012464399 \n'
Cases feedback: https://a.b.com/page/1041338613"


# run!
java -jar "$filename" -uid "$uid" -text "$text"

In other words:

  1. Leave carriage returns unescaped.
  2. Put java command line arguments inside double quotes.
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74