Re: What shell feature did surprise you?
- From: Geoff Clare <geoff@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 27 May 2011 14:09:24 +0100
Stephane CHAZELAS wrote:
2011-05-27, 13:01(+02), Janis Papanagnou:
Just remembered... - I had been surprised by a function definition
with (subshell-)parenthesis instead of curly braces around the
function body ; with all consequences, as in the subsequent example...
In all Bourne-like shells but bash, the syntax is
foo() any-command
so can be
foo() echo test
f() g() { echo test; }
foo() { ...; }
foo() ( ...; )
foo() for i do
echo "<$i>"; done
bash and POSIX only allow compound commands (so all but the
first 2 above).
In POSIX the syntax is:
fname() compound-command[io-redirect ...]
I can remember being surprised about that io-redirect when I came
across it in the standard in the mid 1990's.
$ ls
$ func() { echo foo; } > "$func_out"
$ func_out=file1; func
$ func_out=file2; func
$ ls
file1 file2
--
Geoff Clare <netnews@xxxxxxxxxxxxx>
.
- Follow-Ups:
- Re: What shell feature did surprise you?
- From: Stephane CHAZELAS
- Re: What shell feature did surprise you?
- References:
- What shell feature did surprise you?
- From: Jens Schweikhardt
- Re: What shell feature did surprise you?
- From: Janis Papanagnou
- Re: What shell feature did surprise you?
- From: Stephane CHAZELAS
- What shell feature did surprise you?
- Prev by Date: Re: Ping an ip address range
- Next by Date: Re: IP range regex question
- Previous by thread: Re: What shell feature did surprise you?
- Next by thread: Re: What shell feature did surprise you?
- Index(es):
Relevant Pages
|