I need to execute a bash script containing SQL, so I am using a script to add custom configurations to a Postgres Docker container, according to the docs here:
https://github.com/docker-library/docs/tree/master/postgres#how-to-extend-this-image
But I don't know what EOSQL
means. Here is an example of my script taken from the docs above:
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER docker;
CREATE DATABASE docker;
GRANT ALL PRIVILEGES ON DATABASE docker TO docker;
CREATE EXTENSION $MY_EXTENSION;
EOSQL
So, what is EOSQL? I cannot seem to find much information about this command or keyword.
EOSQL
is a limit string for a Bash Here Document block. It signifies the start and end of a text block to the bash interpreter. The limit string can be any text that doesn't appear in your block.
Variable substitution will work as normal in a here document:
#!/usr/bin/env bash
cat <<-EOF
$MY_EXTENSION
EOF
Then running that with the variable set:
$ MY_EXTENSION=something ./test.sh
something
In Docker you will need ENV MY_EXTENSION=something
in your Dockerfile
or docker run -e MY_EXTENSION=something <image>
on your command line for the environment to be setup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With