This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: functions in /bin/sh scripts causing "unexpected "("" errors


----Original Message----
>From: Kristin Wright
>Sent: 17 August 2005 19:03

> I'm observing the following error when I attempt to run shell scripts
> with  functions in a cygwin shell. These scripts work as expected on
> my linux machines.

> $ ./functest
> ./functest: 3: Syntax error: "(" unexpected
> $ cat functest
> #!/bin/sh
> 
> function helloworld () {
>         echo "Hello, World!"
> }
> 
> helloworld();

  Oh, really?

  On my RH8 box I just get:

------------------------------<snip!>------------------------------
[dk@pepper dk]$ cat foo.sh
#!/bin/sh

function helloworld() {
        echo "Hello, World!"
}

helloworld ();

[dk@pepper dk]$ ./foo.sh
./foo.sh: line 7: syntax error near unexpected token `;'
./foo.sh: line 7: `helloworld ();'
------------------------------<snip!>------------------------------

  This isn't C.  To invoke helloword, you just put it as a line on it's own:

> helloworld

  If you wanted to pass args, they would just be words following the
command:

> helloworld arg1 arg2 arg3

  The brackets are only used in the definition, not the invocation.

> I'm guessing that this is a bug in this particular version of sh on
> cygwin 

  On cygwin, sh is in fact bash.  At least, it is these days.  Formerly, it
used to be ash, and that's the version you have on your machine; and the
syntax for functions you are using only works in bash.

  Either specify /bin/bash in the shebang, or update your cygwin install
(specifically the bash package).

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]