1

I get an error while executing the following psql statement inside a bash script:

execlog "psql -h $HOST -p $PORT -U $USER -d $DB -q -c 'CREATE EXTENSION hstore;'"

The raised error is:

ERROR: unterminated quoted string at or near "'CREATE" LINE 1: 'CREATE ^

Thus, the single terminating quote is not recognize as it should be. When using escaped double quotes instead single quotes (...\"CREATE EXTENSION hstore;\") I get the same error. When executing the command directly from the command line, everything works fine.

Does someone know what's going wrong?

To give some additional info:

OS: Ubuntu 11.10, Postgresql Verion: 9.1

Thanks in advance, Richard

Solved: The execlog function produces the error. Now I am calling

log "exec psql -h $HOST -p $PORT -U $USER -d $DB -q -c 'CREATE EXTENSION hstore;'"

which works fine!

Thanks for your help!

1
  • 1
    for bash debugging set -x, this will write to stderr the command being executed. then you can see what gets passed to psql. Commented Aug 1, 2012 at 12:20

1 Answer 1

1

The problem is that after quote removal, the single quotes are no longer treated as syntax to escape the space, but literal characters as part of the string. Try

execlog psql -h $HOST -p $PORT -U $USER -d $DB -q -c 'CREATE EXTENSION hstore;'

(I can't find any information on execlog, so I don't know if the above will work.)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your pointer to execlog (an own function in our library). This produces the error...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.