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*

10
  • Um.. it improves: when login and alias, I see: alias psql-local='read -p \"PSQL: enter the DB to connect: \" db ; sudo -i -u postgres psql --dbname "$db"', but when I use it, I see error: > psql-local \n "PSQL:jfps \n -bash: read: `connect:': not a valid identifier \n psql: option '--dbname' requires an argument \n Try "psql --help" for more information. Seems the script is truncated due to single quotes. Commented Feb 1, 2019 at 9:33
  • I also tried: 1) single quote $db; 2) escape " and double quote $db 3) double quote $db without escaping. But no avail. Commented Feb 1, 2019 at 9:40
  • try prepending a printf "{%s} " before sudo ... and tell me the output you're getting. Commented Feb 1, 2019 at 9:42
  • OK so I changed back to your solution (single quote all) and add what you said, and I got same error as before, but with extra {}. Seems empty {%s}. Commented Feb 1, 2019 at 9:46
  • 1
    The best thing is to use set -x and the printf "{%s} " ... trick when in doubt. Anyways, variables ($x) and other $ expansions are performed inside double quotes ("...") but not inside single quotes ('...'). Commented Feb 1, 2019 at 10:03