Lots of good, robust solutions; but here is a bash one-liner to keep in the ol' grimoire:
psql -Atqc "SELECT 'DROP DATABASE ' || quote_ident(datname) || ';' FROM pg_database WHERE datname like '%june%';" | psql
This uses a SELECT statement that builds some strings around the datnames returned by a query against the pg_database table.
SELECT 'DROP DATABASE ' || quote_ident(datname) || ';'
FROM pg_database WHERE datname like '%june%';
This is executed directly from the shell using arguments to psql to:
-A Turn off fill justification when printing out table
elements.
-t Turn off printing of column names and result row
count. This is useful with the -c option in shell
scripts.
-q Specifies that psql should do its work quietly. By
default, it prints welcome and exit messages and
prompts for each query. If this option is used,
none of this happens. This is useful with the -c
option.
-c query Specifies that psql is to execute one query string,
query, and then exit. This is useful for shell
scripts, typically in conjunction with the -q
option in shell scripts
All of this is then piped into another invocation of psql with | psql when then executes the DROP DATABASE queries