Escaping the and (&) sign in Powershell

When calling from cmd.exe, things get tricky; here’s a simplified example: powershell -c “ffmpeg.exe -h “^””User-Agent: usra`r`nCookies: parm=a=1&b=2; session=1″^””” In short: From cmd.exe / batch files, to pass what PowerShell’s CLI should see as a double-quoted argument inside an overall “…” string passed to -Command (-c): In Windows PowerShell (powershell.exe): use “^””…”^”” (sic) In PowerShell … Read more

‘kubectl patch’ works on Linux Bash but not in Windows Powershell ISE

For detailed and very useful background, see the answer by mklement0 After much frustration, I have decided to list all variants of quote escaping that I’ve tried, and came up with one more, which suddenly worked! So, sharing it here: kubectl patch deployment wapi-backend-d1 –patch ‘{\”spec\”: {\”template\”: {\”metadata\”: {\”labels\”: {\”date\”: \”test123\”}}}}}’ This is how to … Read more

Build a JSON string with Bash variables

You are better off using a program like jq to generate the JSON, if you don’t know ahead of time if the contents of the variables are properly escaped for inclusion in JSON. Otherwise, you will just end up with invalid JSON for your trouble. BUCKET_NAME=testbucket OBJECT_NAME=testworkflow-2.0.1.jar TARGET_LOCATION=/opt/test/testworkflow-2.0.1.jar JSON_STRING=$( jq -n \ –arg bn “$BUCKET_NAME” … Read more

Powershell: passing json string to curl

Try using the –% operator to put PowerShell into simple (dumb) argument parsing mode: curl.exe –% -ku user@email:mypass -X PUT -d “data={\”password\”:\”keypass\”}” https://build.phonegap.com/api/v1/key This is quite often useful for invoking exes with argument syntax that runs afoul of PowerShell’s argument syntax. This does require PowerShell V3 or higher.

How to escape single quotes within single quoted strings

If you really want to use single quotes in the outermost layer, remember that you can glue both kinds of quotation. Example: alias rxvt=”urxvt -fg “”‘”‘#111111′”‘”‘ -bg ‘”‘”‘#111111′”‘” # ^^^^^ ^^^^^ ^^^^^ ^^^^ # 12345 12345 12345 1234 Explanation of how ‘”‘”‘ is interpreted as just ‘: ‘ End first quotation which uses single quotes. … Read more