How do I use shell variables in Makefile actions?

There are at least two considerations. $() references a Make variable. You must escape the $ to do command substitution. Also, the shell commands must be all on one line. Try:

exists=$$(psql postgres --tuples-only --no-align --command "SELECT 1 FROM \
    pg_database WHERE datname="the_db""); \
    if [ "$$exists" -eq 1 ]; then \
        dropdb the_db; \
    fi; \
    createdb -E UTF8 the_db

On the other hand, it seems like it would be simpler to just always try to drop the database, and allow failure:

rebuilddb:
    -dropdb the_db  # Leading - instructs make to not abort on error
    createdb -E UTF8 the_db

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)