whoisearth
whoisearth

Reputation: 4170

shell script variable not passing

I have a snippet of a shell script like so -

status() {
        if [ -x "$PRGDIR/qtcat_ctl.sh" ]; then
                echo "Status-ing qtcat Server"

                if [ -z "$QTCAT_RUNTIME_USER" ]; then
                        eval $PRGDIR/qtcat_ctl.sh status
                else
                        su - $QTCAT_RUNTIME_USER -c $PRGDIR/qtcat_ctl.sh status
                fi

                RETVAL=$?
        else
                echo "Startup script $PRGDIR/qtcat_ctl.sh doesn't exist or is not executable."
                RETVAL=255
        fi
}

If QTCAT_RUNTIME_USER is set to "" the script runs fine but if I try to set QTCAT_RUNTIME_USER to another account the status parameter does not get passed to the qtcat_ctl.sh script.

Upvotes: 0

Views: 644

Answers (1)

V. Michel
V. Michel

Reputation: 1619

If you need to send an argument to your program via su, you have to quote all the command.

Example with the program a.sh :

$ cat a.sh
echo a.sh $1

$su - $USERNAME -c $PWD/a.sh test
a.sh
$su - $USERNAME -c "$PWD/a.sh test"
a.sh test

Upvotes: 1

Related Questions