I need to run this command
psql -c "create database $var with encoding 'unicode';" -U edumate template1
from the script under different user. The su syntax is su postre -c 'some command' so there are another quotes required. Also please note that the psql command has $var variable inside.
so ‘some command’ = psql -c “create database $var with encoding ‘unicode’;” -U edumate template1
and ‘some command’ must be enclosed in quotes too (I guess)
There’s a trick you can use anytime you need to have the shell accept as a single argument something that has both single quotes and double quotes. Because the shell won’t let you escape quotes, you need to turn it into multiple abutting quoted strings, switching between single and double quotes as needed to protect what’s inside. It’s ugly, but it works. For example, to have
be a single argument, you could abut the three strings:
to get:
In your case that would give a very ugly: