user6672948 user6672948 - 5 months ago 16
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!


I suggest to replace

json_format ${questions[$Q_counter]}


json_format "${questions[$Q_counter]}"