delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/08/17/14:16:25

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
Subject: RE: functions in /bin/sh scripts causing "unexpected "("" errors
Date: Wed, 17 Aug 2005 19:16:12 +0100
MIME-Version: 1.0
In-Reply-To: <cc4b99fe05081711021dba7a3e@mail.gmail.com>
Message-ID: <SERRANOyFksCW9DXc9g000000d4@SERRANO.CAM.ARTIMI.COM>

----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 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 ();'
------------------------------<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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019