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

The service for a piece of software I just installed (from a provided .deb file) on a Ubuntu server won't start. When running the service I get the error:

/etc/init.d/matrixsa: 44: Syntax error: "}" unexpected (expecting "fi")

Here is the relevant part of the script. Not being versed in shell scripting I don't know if this is valid:

if [ -f /etc/rc.d/init.d/functions ]
    . /etc/rc.d/init.d/functions
    function action {
        echo "$1"
    } # <-- this is line 44
    function success {
        echo -n "Success"
    function failure {
        echo -n "Failed"
share|improve this question
Are you running it with bash or plain sh? See this list of bashisms – hhaamu Dec 7 '11 at 12:44
up vote 13 down vote accepted

$@ could contain anything, even things which make your function suddenly syntactically invalid. Quote it instead. Here is a less breakable version of the script:

if [ -f /etc/rc.d/init.d/functions ]; then
    . /etc/rc.d/init.d/functions
    action() {
        printf '%s\n' "$1"
    success() { printf Success ; }
    failure() { printf Failed ; }

If you are using bash or similar, you could use the following as the action function:

action() {
    printf '%s\n' "$1"

If it is important that it splits on IFS like the original script (it probably isn't), unquote $@.

It's also possible that you're running this in a non-bash shell. function is a bashism, use func() instead.

share|improve this answer
+1, "$@" probably has the single largest utility/use factor of all the Bash idioms. Use More Quotes :) – l0b0 Dec 7 '11 at 12:45
Thanks, this worked great. – DisgruntledGoat Dec 7 '11 at 14:57

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.