I have an array in bash which consists of string messages.
I need to use these messages as dictionary values in python. Something like this:
**Array in Bash**
errorMessage+=("testing the message")
errorMessage+=("this is msg2")
**Function with Python code in Bash**
displayJsonOutput()
{
python - <<END
import json
dict1 = {}
dict1['ScriptName']="$scriptName";
dict1['CaseName']="$option"
dict4={}
dict4['LogFile']="$logFileName";
dict4['ReportFile']="$reportFileName";
for idx in "${!errorMessage[@]}":
dict4["Message $((idx + 1))"]="${errorMessage[$idx]}";
dict1["Details"]=dict4
print(json.dumps(dict1, indent=4))
END
}
Output shown:
"Details": {
"LogFile": "/home/output.log",
"Message 1": "testing the message",
"ReportFile": "/home/out.rpt"
},
When I try this, it only shows the first message value. does not go through the loop for errorMessage. I want the json output values should look like below for errorMessage:
"Details": {
"LogFile": "/home/output.log",
"Message 1": "testing the message",
"Message 2": "this is msg2",
"ReportFile": "/home/out.rpt"
},
pythondictionary?