`echo "thing and stuff"` vs `echo thing and stuff` | Windows works whilst *nix fails
Describe The Bug
Quoting for piping into psql doesn't work cross-platform.
To Reproduce
For example this works on Windows:
[tasks.init]
script_runner = "@shell"
script = '''
echo CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMARY KEY GENERATED ALWAYS as identity, created_at TIMESTAMP DEFAULT now(), content TEXT); | psql ${POSTGRES_URI}
echo INSERT INTO task_logger_tbl(content) VALUES ('tasks.init'); | psql ${POSTGRES_URI}
'''
And this works on Linux:
[tasks.init]
script_runner = "@shell"
script = '''
echo "CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMARY KEY GENERATED ALWAYS as identity, created_at TIMESTAMP DEFAULT now(), content TEXT);" | psql ${POSTGRES_URI}
echo "INSERT INTO task_logger_tbl(content) VALUES ('tasks.init');" | psql ${POSTGRES_URI}
'''
(but the Linux variant doesn't work on Windows; and the Windows variant doesn't work on Linux)
For example, run docker run -p 5432:5432 -e POSTGRES_USER=rest_user -e POSTGRES_PASSWORD=rest_pass -e POSTGRES_DB=rest_db postgres:alpine and add this to your env:
[env]
POSTGRES_URI = "postgresql://rest_user:[email protected]:5432/rest_db"
Then run the software and you'll get:
Windows
(unquoted echo)
my_dir>echo CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMARY KEY GENERATED ALWAYS as identity, created_at TIMESTAMP DEFAULT now(), content TEXT); | psql postgresql://rest_user:[email protected]:5432/rest_db
CREATE TABLE
my_dir>echo INSERT INTO task_logger_tbl(content) VALUES ('tasks.init'); | psql postgresql://rest_user:[email protected]:5432/rest_db
INSERT 0 1
(quoted echo)
my_dir>echo "CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMARY KEY GENERATED ALWAYS as identity, created_at TIMESTAMP DEFAULT now(), content TEXT);" | psql postgresql://rest_user:[email protected]:5432/rest_db
NOTICE: identifier "CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMARY KEY GENERATED ALWAYS as identity, created_at TIMESTAMP DEFAULT now(), content TEXT);" will be truncated to "CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMARY K"
ERROR: syntax error at or near ""CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMARY KEY GENERATED ALWAYS as identity, created_at TIMESTAMP DEFAULT now(), content TEXT);""
LINE 1: "CREATE TABLE IF NOT EXISTS task_logger_tbl(id INTEGER PRIMA...
^
my_dir>echo "INSERT INTO task_logger_tbl(content) VALUES ('tasks.init');" | psql postgresql://rest_user:[email protected]:5432/rest_db
ERROR: syntax error at or near ""INSERT INTO task_logger_tbl(content) VALUES ('tasks.init');""
LINE 1: "INSERT INTO task_logger_tbl(content) VALUES ('tasks.init');...
^
Linux
(quoted echo)
INFO - Running Task: init
CREATE TABLE
INSERT 0 1
(unquoted echo)
INFO - Running Task: init
/tmp/fsio_HYtNSXnHo4.sh: 3: Syntax error: "(" unexpected
Error while executing command, exit code: 2
i created this solution before duckscript, but with duckscript, why use this? and if you must, you can always force a certain conversion:
#provide custom windows command for specific shell command
complex_bash_command --flag1 value2 # shell2batch: complex_windows_command /flag10 windows_value
@sagiegurari Oh I thought with echo being such a useful and often builtin command maybe the expectation are that it would be handled specially by this library.
So duckscript is recommended over @shell? - Ok will rewrite in duckscript.
i would love echo to work well but dodnt get whats the recommendation/proposal