bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function grammar


From: Linda Walsh
Subject: Re: function grammar
Date: Sun, 18 Jul 2010 20:53:44 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666

The curly brackets are suposed to be optional.
They are line "2" of the Compound commands list below...

Clark J. Wang wrote:
On Mon, Jul 19, 2010 at 2:53 AM, Linda Walsh <bash@tlinx.org <mailto:bash@tlinx.org>> wrote:



    from man bash, to define a function use;

    "function" "name" <compound-command>
     OR
    "name" () <compound-command>

    right?

    And Compound Commands are:

     ( <list>)
     { <list>; )
     (( expression ))
     [[ expression ]]
    ...et al....

    so why do I get a syntax error for

    function good_dir [[ -n $1 && -d $1 && -r $1  && -x $1 ]]

    bash: syntax error near unexpected token `[['

You should enclose the function body code in between `{' and `}':

function good_dir { [[ -n $1 && -d $1 && -r $1  && -x $1 ]]; }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]