Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to understand the script below and I am confused about the su line. I understand the postgres command line arguments.

when I do man su the manual says

-c, --command=COMMAND pass a single COMMAND to the shell with -c

However the line with the su - postgres -c ... seems to contain two commands

  • first one setting the LD_LIBRARY environment variable
  • second one calling pg_ctl

So are there two commands being passed with -c or one ?

        echo $"Starting PostgreSQL 9.1: "
        su - postgres -c "LD_LIBRARY_PATH=/opt/PostgreSQL/9.1/lib:$LD_LIBRARY_PATH /opt/PostgreSQL/9.1/bin/pg_ctl -w start -D \"/opt/PostgreSQL/9.1/data\" -l \"/opt/PostgreSQL/9.1/data/pg_log/startup.log\""

        if [ $? -eq 0 ];
                echo "PostgreSQL 9.1 started successfully"
                exit 0
                echo "PostgreSQL 9.1 did not start in a timely fashion, please see /opt/PostgreSQL/9.1/data/pg_log/startup.log for details"
                exit 1
share|improve this question
Hint: use scripting. – innocent-world Aug 23 '13 at 9:30
up vote 9 down vote accepted

It's a single command passed to the shell. The shell allows you to set environment variables on a per-command basis, eg:

PGPORT=5433 psql

su invokes the shell with its argument, so:

su -c 'PGPORT=5433 psql'

is like doing:

exec bash -c 'PGPORT=5433 psql'

Frankly, I tend to prefer using sudo, which makes setting environment variables easy and handles commands with complex quoting properly because it doesn't go via the shell.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.