user6672948 user6672948 - 1 year ago 53
JSON Question

bash function input $1 is only processing first word of string & formatting issue

My BASH function:

json_format () {
echo '{
"question": "';echo "$1";echo '",'


json_format ${questions[$Q_counter]}

Is returning:

"question": "

Instead of expected json format and string:

"question": "VM CPU is at 100% and you'r jumpbox creds be broken! What do you do?",

The string appears to be cut off at the space after the first word "VM", and the formatting is a little off with those echo commands. How can i correct my function? Thanks!

Answer Source

I suggest to replace

json_format ${questions[$Q_counter]}


json_format "${questions[$Q_counter]}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download