0

I have an alias which is my psql connection string for a database, let's say the alias is this:

alias GQQ='psql "host=$host user=$redshift_uname dbname=$redshift_dbname port=$port pass word=$redshift_pwd"'

This alias exists so I can connect to the database, but I would also like to call it within a function to send simple queries to the database.

In regular terminal I can run first: GQQ <<EOF second: <QUERY> ex. SELECT * FROM table LIMIT 10; and third: EOF, and my query will return results.

I would like to create function which emulates this as follows:

function qredshift() {
GQQ &lt;&lt;EOF
$*
EOF

}

But I am unsure how to formulate this, I have tried shell within shell and adding quotes in various place, what is the proper way to run this?

Kusalananda
  • 333,661
  • You can use a herestring to avoid dealing with the indentation and tab requirements of a heredoc: GQQ <<< "$*". – Gairfowl Sep 23 '22 at 20:46