[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function grammar
From: |
Ken Irving |
Subject: |
Re: function grammar |
Date: |
Sun, 18 Jul 2010 22:30:38 -0800 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Sun, Jul 18, 2010 at 11:53:02AM -0700, Linda Walsh 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 `[['
I see this in bash(1):
SHELL GRAMMAR
...
Shell Function Definitions
...
[ function ] name () compound-command [redirection]
and do not see the version you show without the parens.
$ function good_dir() [[ -n $1 && -d $1 && -r $1 && -x $1 ]]
$ good_dir; echo $?
1
$ good_dir /tmp; echo $?
0
Ken
Re: function grammar, Chet Ramey, 2010/07/20