PostgreSQL 9.4, Debian 8.1
It works with this script
#!/bin/bash
pg_dump -h 127.0.0.1 -U postgres -T 'loolz_*' wazap -f /tmp/wazap.sql
exit 0
but not with this one
#!/bin/bash
dumpcommand="pg_dump -h 127.0.0.1 -U postgres -T 'loolz_*' wazap -f /tmp/wazap.sql"
$dumpcommand
exit 0
Please help me to understand why the second option does not work, I tried to play with brackets and quotes. Nothing helps…
In Case someone will read this: Bash escaping is the Problem here:
bash -vx ./test.sh
#!/bin/bash
dumpcommand="pg_dump -h 127.0.0.1 -U postgres -T 'loolz_*' wazap -f /tmp/wazap.sql"
+ dumpcommand='pg_dump -h 127.0.0.1 -U postgres -T '\''loolz_*'\'' wazap -f /tmp/wazap.sql'
$dumpcommand
+ pg_dump -h 127.0.0.1 -U postgres -T ''\''loolz_*'\''' wazap -f /tmp/wazap.sql
You can resolve the problem via the following:
bash -vx ./test.sh
#!/bin/bash
exclude='loolz_*'
+ exclude='loolz_*'
dumpcommand="pg_dump -h 127.0.0.1 -U postgres -T ${exclude} wazap -f /tmp/wazap.sql"
+ dumpcommand='pg_dump -h 127.0.0.1 -U postgres -T loolz_* wazap -f /tmp/wazap.sql'
$dumpcommand
+ pg_dump -h 127.0.0.1 -U postgres -T 'loolz_*' wazap -f /tmp/wazap.sql
Maybe this will help anyone