Re: What shell feature did surprise you?
- From: Stephane CHAZELAS <stephane_chazelas@xxxxxxxx>
- Date: Fri, 27 May 2011 14:11:24 +0000 (UTC)
2011-05-27, 14:09(+01), Geoff Clare:
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
Yes, and I remember now that zsh is not conformant there as it
performs the redirection at the time of the function definition
in the f() { echo a; } > x
http://www.zsh.org/mla/workers/2008/msg01674.html
So it's even less clear why POSIX doesn't allow
f() echo x
would you know?
--
Stephane
.
- Follow-Ups:
- Re: What shell feature did surprise you?
- From: Geoff Clare
- 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
- Re: What shell feature did surprise you?
- From: Geoff Clare
- What shell feature did surprise you?
- Prev by Date: Re: IP range regex question
- Next by Date: Re: rename file contents with its directory name as a prefix
- Previous by thread: Re: What shell feature did surprise you?
- Next by thread: Re: What shell feature did surprise you?
- Index(es):
Relevant Pages
|