NikolayS / postgres_dba

The missing set of useful tools for Postgres DBAs and all engineers
BSD 3-Clause "New" or "Revised" License
1.12k stars 116 forks source link

make echo for .psqlrc work both for bash and zsh #51

Closed NikolayS closed 3 years ago

NikolayS commented 3 years ago

@unhandled-exception please check it if you have a minute. Thanks.

unhandled-exception commented 3 years ago

@unhandled-exception please check it if you have a minute. Thanks.

This method is not works on zsh and csh (FreeBSD, OSX):

echo "\\set dba '"'\''\'"i `pwd`/postgres_dba/start.psql'"

zsh:
\set dba '\i /home/aquila/postgres_dba/start.psql'

bash:
\set dba '\\i /home/aquila/postgres_dba/start.psql'

csh:
\\set dba '\\i /usr/home/aquila/postgres_dba/start.psql'

I found an alternative method:

printf "%s %s %s %s\n" \\set dba \'\\\\i `pwd`/postgres_dba/start.psql\'

zsh:
\set dba '\\i /home/aquila/postgres_dba/start.psql'

bash:
\set dba '\\i /home/aquila/postgres_dba/start.psql'

csh:
\set dba '\\i /usr/home/aquila/postgres_dba/start.psql'

It's works on FreeBSD, Linux and OSX :)