4

PSVersion 5.1.22621.4391

plink: Release 0.82

I've pored through Properly escape awk command from powershell over plink but one of those programs keeps eating single quotes.

Is there any way to run this command through plink?

echo "select setting from pg_settings where name = 'server_version';"

Examples of my failure:

PS C:\Users> plink -load "FIS-S-LBX-PGS-202-a" -batch echo "select setting from pg_settings where name = 'server_version';"
select setting from pg_settings where name = server_version

PS C:\Users> plink -load "FIS-S-LBX-PGS-202-a" -batch echo --% "select setting from pg_settings where name = 'server_version';" select setting from pg_settings where name = server_version

PS C:\Users> plink -load "FIS-S-LBX-PGS-202-a" psql -c --% 'select setting from pg_settings where name = ''server_version'';' Access granted. Press Return to begin session. ERROR: column "server_version" does not exist LINE 1: select setting from pg_settings where name = server_version;

PS C:\Users> plink -load "FIS-S-LBX-PGS-202-a" -batch psql -c "select setting from pg_settings where name = 'server_version';" psql: warning: extra command-line argument "pg_settings" ignored

[snip]

PS C:\Users> plink -load "FIS-S-LBX-PGS-202-a" -batch psql -c --% "select setting from pg_settings where name = 'server_version';"
psql: warning: extra command-line argument "pg_settings" ignored
RonJohn
  • 403

1 Answers1

6

You were close with your last one -- that stops PS eating the (double)quotes, but plink is equally quotivorous so you need backslash to stop that:

plink -load session -batch psql -c --% \"select blah blah;\"

Or you can instead stop PS with backtick then plink with backslash:

plink -load session -batch psql -c \`"select blah blah;\`"

(but to me that's just ugly!)

It's actually the remote shell that was eating the singlequotes, and once you get plink to send the doublequotes that both stops the remote shell and provides a single argument to -c as required.