I need to create a wrapper script for PHP interpreter (already in PATH):

# This is a wrapper for the PHP interpreter.
# We prepare the enviroment for SQL Anywhere PHP extension sourcing
# /opt/sqlanywhere17/bin64/sa_config.sh and then we call the PHP
# interpreter already in the PATH passing -dextension=sqlanywere.so which
# enable the PHP extension.
# Don't enable sqlanywhere.so globally becase for some reason this will
# break the command "plesk bin php_handler". In addition the extension
# requires the SQLANY17 environment variable which is hard to set with
# CGI/FastCGI at this time.
php $@

My php-wrapper however is not working properly with quotes. For example, this works with the original interpreter:

php-r 'echo "Works";'

Running php-wrapper with the same arguments:

./php-wrapper -r 'echo "Works";'

PHP Parse error: syntax error, unexpected end of file in Command line code on line 1

How can I debug arguments $@ to see what's happening and how can I solve this problem?

1 Answer 1


Wrap your $@ in double quotes, thusly:

php "$@"

What's happening is that the arguments to php-wrapper are -r and echo "Works"; which is fine. However, because $@ isn't quoted, all the arguments php-wrapper receives are parsed as separate words, so php is being passed -r, echo, and "Works". With the double-quoted $@, php will be passed -r and echo "Works".

From the bash manual page:

   @      Expands to the positional parameters, starting from  one.   When
          the  expansion  occurs  within  double  quotes,  each  parameter
          expands to a separate word.  That is, "$@" is equivalent to "$1"
          "$2"  ...

Here's a little script I use when argument parsing isn't happening the way I want it to:

$ cat echoargs
#!/bin/bash --


for i in "$@"
    echo "$count: $i"


Change your wrapper script to:

echoargs $@
echo ====
echoargs "$@"

and then try various invocations of the wrapper to see what it's passing on.

You must log in to answer this question.

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