Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • 1
    Please also include the command that works Commented Jul 5, 2024 at 11:26
  • 1
    Please add all relevant information to the question body. Comments are hard to read, easy to miss and can be deleted without warning. The error seems to be from postgres, by the way, not the shell. do you perhaps need to do some special quoting in postgres, like `my_table`? Commented Jul 5, 2024 at 11:57
  • 1
    If not, can you try drop_db=(DROP DATABASE "${db1}") and then sudo -u postgres -S /bin/bash -c "psql -U postgres -d postgres -c '${drop_db[@]}'", does that work? Commented Jul 5, 2024 at 12:00
  • 1
    @CodeWeed: Why are you calling bash to call psql instead of calling psql directly? Feels like some quoting is likely being eaten up in this layering. Commented Jul 5, 2024 at 12:11
  • 1
    right, right, and that's what Chris was getting at. You're right, @ilkkachu, I'm thinking of shell tokenization but it is psql that's relevant here. Commented Jul 5, 2024 at 12:46