Insert PBKDF2 hash into PostgreSQL container I am using the PostgreSQL docker image with the following Dockerfile:

FROM postgres:10.1

COPY init-db.sh /docker-entrypoint-initdb.d/init-db.sh


and an init-db.sh script with the following content:

#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" &lt;&lt;-EOSQL
    CREATE DATABASE foodb;

    \c foodb;
    DROP TABLE IF EXISTS users;

CREATE TABLE users (
    id SERIAL,
    username VARCHAR(25) NOT NULL,
    pw VARCHAR(128) NOT NULL,
    super INT NOT NULL DEFAULT 0,
    PRIMARY KEY (id)
  );

CREATE UNIQUE INDEX users_username ON users (username);

INSERT INTO users (username, pw) 
VALUES ('jjolie', 
        'PBKDF2$sha256$901$x8mf3JIFTUFU9C23$ic9J6mFDSz0rETKux/Co9TzCPOX50j+V8Vky5GkY5v0=');


After building the container (with the init-db script included) with docker build . --tag postgres, when the container is started with docker run postgres, and the users table is viewed:

docker exec -it postgres bash
psql -U postgres
\c foodb
select * from users;


We see the following output:

 id | username |                   pw                    | super
----+----------+-----------------------------------------+-------
  1 | jjolie   | PBKDF201/Co9TzCPOX50j+V8Vky5GkY5v0=     |     0


PBKDF201/Co9TzCPOX50j+V8Vky5GkY5v0= differs from PBKDF2$sha256$901$x8mf3JIFTUFU9C23$ic9J6mFDSz0rETKux/Co9TzCPOX50j+V8Vky5GkY5v0='.

Why did the password change from PBKDF2$... to PBKDF201..? How can it be prevented?
Because the variables are replaced (with nothing) in bash, the dollars signs need to be escaped:

'PBKDF2\$sha256\$901\$x8mf3JIFTUFU9C23\$ic9J6mFDSz0rETKux/Co9TzCPOX50j+V8Vky5GkY5v0='