It is necessary in the bash script to check whether the specified psql database exists or not. Are there any regular funds?

For files there is a construction: if [ -f $FILE ]; then if [ -f $FILE ]; then For psql - maybe there is something of their own. Or maybe you should dig in the direction of the physical search for the database itself in the file format?

    1 answer 1

    Apparently you need something like this:

     if psql -lqt | cut -d \| -f 1 | grep -qw <db_name>; then #база существует else #база не существует fi 

    Original on stackoverflow.com

    • Akalnq, yes, this option is almost suitable! The only thing grip with the keys- -qw does not give me anything sensible. If it is completely without keys - it works, but there is no uniqueness) if there are 3 bases a la db_test, db_test1, db_test2 - then on request db_test I will see all three) - Dofri