How to return a value from psql to bash and use it?
Try:
LAST_VALUE=`echo "SELECT last_value FROM my_seq;" | psql -qAt -d database_name`
You can capture the result of a command using the VAR=$(command) syntax:
VALUE=$(psql -qtAX -d database_name -f get_seq.sql)
echo $VALUE
The required psql options mean:
-t
only tuple
-A
output not unaligned
-q
quiet
-X
Don't run .psqlrc file