Cmd line escape characters

2/15/2022

I'm translating a service manual from Linux to Windows command line, and running into some issues with escape characters. After looking at other entries here and general googling I haven't been able to find anything that works for whatever reason.

In this line:

kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "demo-registry"}]}' -n testNamespace

I'm unable to find a combination of <code>`</code>, ^, or \ that allows me to escape the double quotes. I was able to get it to work in the powershell command below though.

kubectl patch serviceaccount default -p "{\`"imagePullSecrets\`": [{\`"name\`": \`"demo-registry\`"}]}" -n testNamespace
-- Nyyen8
cmd
kubernetes
windows-10

1 Answer

2/17/2022

Inverting the " and 's around the inputs allows the command to run without needing escape characters. The errors I had received were in part due to issues with my local environment.

kubectl patch serviceaccount default -p "{'imagePullSecrets': [{'name': 'demo-registry'}]}" -n testNamespace
-- Nyyen8
Source: StackOverflow