0

I'm trying to read database (PostgreSQL) connection string from GitHub secrets and use it in GitHub action to apply database migrations through EF Core Migration Bundles. The part of the action responsible to perform this job has similar bash script:

#!/bin/bash

doubleQuote="\""
connectionString=Host=host;Username=username;Password=password;Database=database;Persist Security Info=true;

connectionString="${doubleQuote}${connectionString}${doubleQuote}"

echo $connectionString

The value with which the shell variable connectionString is initialized actually comes from GH secrets (note the absence of enclosing double quotes). I need to enclose it basically. I'm getting the following error when running:

./b.sh: line 4: Persist: command not found "Host=host"

To escape white spaces and semicolons, I tried to replace them as follows:

#!/bin/bash

doubleQuote="\""
connectionString=Host=host;Username=username;Password=password;Database=database;Persist Security Info=true;

connectionString="${connectionString//;/\\;}"
connectionString="${connectionString// /\\_}"
connectionString="${doubleQuote}${connectionString}${doubleQuote}"

echo $connectionString

but its not working. What is the correct way to achieve this?

Objective is to enclose it with double quotes so that Persist Security Info is considered as a portion of the connection string value itself.

  • `connectionString=...` statement will terminate when it encounters `;` giving you syntax error in assignment. – anubhava Feb 09 '23 at 10:50

0 Answers0