PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] What is the `<<-EOSQL` code block in Bash when running SQL?

 August 19, 2022     bash, docker, environment-variables, postgresql     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing