I have tried both methods of escaping the space in the Path in the following script:

#!/bin/bash -x
PGHOME="/Applications/pgAdmin 4.app/Contents/SharedSupport"
$PGHOME/psql --username postgres -c "drop database $1"

I've also tried changing line 2 to:

PGHOME=/Applications/pgAdmin\ 4.app/Contents/SharedSupport

In both cases I get the script error:

./pg10-restoreDb.sh: line 3: /Applications/pgAdmin: No such file or directory

From the shell, I can execute /Applications/pgAdmin\ 4.app/Contents/SharedSupport/psql no problem

What could be causing this error?

  • In the future probably more appropriate to ask on stackoverflow and tag with bash since bash is not Apple-specific, but glad you got an answer pretty quickly here :)
    – Michael Wu
    Mar 6, 2018 at 8:11
  • 1
    The question is perfectly on-topic here
    – nohillside
    Mar 6, 2018 at 9:11

1 Answer 1


You can either quote or escape the space when you define the variable, but then you must also double-quote it when you use it:

#!/bin/bash -x
PGHOME="/Applications/pgAdmin 4.app/Contents/SharedSupport"
"$PGHOME/psql" --username postgres -c "drop database $1"
^            ^
|            |
  • Thank you! This solved MY issue too (after I'd already spent 15 min on it).
    – Jay
    Aug 19, 2020 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .