template parsing error: template: :1: unexpected "=" in operand
I got the above error when executing the below command in Windows,
docker inspect --format="{{range $key, $value := .Config.Env}}{{if eq (index (split $value "=") 0) "VERSION"}}{{$value}}{{end}}{{end}}" octopusbi-agent-backend
What could be the issue?
The issue with the
"="symbol, if you use a double quotation(") mark inside the string enclosed with the double quotation(") marks, you have to add a backslash(\) before every double quotation(") mark excluding the first and last double quotation(") mark.example:-
Windows
As I mentioned earlier I changed
"="to\"=\"and after that, I got another issue related to some other string value called"VERSION". For that also I had to change"VERSION"to\"VERSION\"and it worked as I expected.So the final command is,
Ubuntu
I ran the same command in Ubuntu with the starting and ending quotations with single quotation(
') marks and kept the rest of the double quotation(") marks.So the final command is,
Summary
If you use the
docker inspectcommand with the--formatoption,") marks.") mark inside the format string, use\"instead.') marks.") marks inside the format string.In the shortest, we have to use the double quotation(
") mark inside the format string for both environments if you need to use the quotation mark.