Issue
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.
Solution
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
a
$MY_EXTENSION
b
EOF
Then running that with the variable set:
$ MY_EXTENSION=something ./test.sh
a
something
b
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.
Answered By - Matt Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.