Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Dave Korn" To: Subject: RE: functions in /bin/sh scripts causing "unexpected "("" errors Date: Wed, 17 Aug 2005 19:16:12 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit In-Reply-To: Message-ID: ----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: ------------------------------------------------------------ [dk AT pepper dk]$ cat foo.sh #!/bin/sh function helloworld() { echo "Hello, World!" } helloworld (); [dk AT pepper dk]$ ./foo.sh ./foo.sh: line 7: syntax error near unexpected token `;' ./foo.sh: line 7: `helloworld ();' ------------------------------------------------------------ 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/