togatttiのエンジニアメモ

過度な期待はしないでください.

psqlで、冗長な箇所を省き結果を取得する

例えば、PostgreSQLのpg_hba.confのパスだけをpsqlで取りたいとき、

単純に、-cオプションを使うと、

$ psql -c 'SHOW hba_file'
              hba_file
-------------------------------------
 /etc/postgresql/10/main/pg_hba.conf
(1 row)

余分な箇所が混ざる。

その場合、-A -tオプションを追加すると冗長な部分を排除し期待していた結果が取得できる。

$ psql -At -c 'SHOW hba_file'
/etc/postgresql/10/main/pg_hba.conf

今までは、こんな形でシェル芸してた。

$ psql -c 'SHOW hba_file' | grep /etc | sed -e 's/ //'
/etc/postgresql/10/main/pg_hba.conf