Search code examples
bashyamltravis-ci

Yaml with bash: escaping quotes in string


I want to execute command in travis file, it's executed by bash from yaml configuration file:

before_script:
 - psql -c 'create role "user" WITH LOGIN PASSWORD '1234'' -U postgres

But apparently I get the error: ERROR: syntax error at or near ""1234"" and I just don't know how to escape quotes: '


Solution

  • This is not a yaml issue, it only concerns the shell launched by your travis build.

    Single quotes inside single quotes in a shell string are escaped as a double single quotes (see this link out of many others for more info)

    psql -c 'create role "user" WITH LOGIN PASSWORD ''1234''' -U postgres