pg_dump tables exclude doesnt work in bash script

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 :slight_smile: