Running a command in psql `-c` that requires identifier quoting I have created a database schema as "mytest.us" and inside this schema, I have created a table "a.b.c".

When I do 

select * from "mytest.us"."a.b.c";
 year | mydata
------+--------
 2011 | test1
 2010 | test1
(2 rows)


but when I do 

\\! $TARGET/sql -p $PGPORT -d $PGDBNAME -c "select * from "mytest.us"."a.b.c"";

sh: -c: line 0: unexpected EOF while looking for matching `"'

sh: -c: line 1: syntax error: unexpected end of file


How can I specify my table in that situation?
It is very poor practice to misuse reserved words. Frankly, messing with multiple periods ., the table/column separator operator, you deserve any hardships coming to your way. There is no need for funky table names, barring some odd edge cases. The DB should be transparent to applications anyway, so stick to sensible naming.

Escape the inner quotes. As how to do that, depends on your shell. The error message looks like *NIX shell, so try backslash \". Like so: 

"select * from \"mytest.us\".\"a.b.c\"";