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:-
"Hello "your_name"" <-- wrong
"Hello \"your_name\"" <-- correct
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,
docker inspect --format="{{range $key, $value := .Config.Env}}{{if eq (index (split $value \"=\") 0) \"VERSION\"}}{{$value}}{{end}}{{end}}" octopusbi-agent-backend
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,
docker inspect --format='{{range $key, $value := .Config.Env}}{{if eq (index (split $value "=") 0) "VERSION"}}{{$value}}{{end}}{{end}}' octopusbi-agent-backend
If you use the docker inspect
command with the --format
option,
"
) 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.