Related articles |
---|
magic/absurd bash interpreter/compiler ? Avoid9Pdf@gmail.com (2012-12-23) |
Re: magic/absurd bash interpreter/compiler ? miller@yoyo.ORG (J G Miller) (2012-12-24) |
Re: magic/absurd bash interpreter/compiler ? jthorn@astro.indiana.edu (Jonathan Thornburg) (2012-12-24) |
Re: magic/absurd bash interpreter/compiler ? eric@deptj.eu (Eric) (2012-12-24) |
Re: magic/absurd bash interpreter/compiler ? barmar@alum.mit.edu (Barry Margolin) (2012-12-24) |
Re: magic/absurd bash interpreter/compiler ? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2012-12-25) |
Re: magic/absurd bash interpreter/compiler ? eric@deptj.eu (Eric) (2012-12-26) |
Re: magic/absurd bash interpreter/compiler ? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2012-12-28) |
Re: magic/absurd bash interpreter/compiler ? barmar@alum.mit.edu (Barry Margolin) (2012-12-28) |
From: | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
Newsgroups: | comp.compilers,comp.unix.shell,comp.os.linux.misc |
Date: | Fri, 28 Dec 2012 03:17:42 +0000 (UTC) |
Organization: | Aioe.org NNTP Server |
References: | 12-12-014 12-12-018 12-12-020 12-12-021 |
Keywords: | history, design, comment |
Posted-Date: | 28 Dec 2012 10:20:41 EST |
In comp.compilers Eric <eric@deptj.eu> wrote:
(snip, I wrote)
>> One problem with many unix shells is that redirection is done too early.
>> Specifically, before an if test is done.
> I am tempted to think that this is a conceptual misunderstanding, so an
> example would be useful.
From the man page for csh:
"The single-command form of if does output redirection even if the
expression is false and the command is not executed."
echo false > file
if( 1 > 2 ) echo true > file
The if statement will open (and truncate) file before
testing the condition. At least for csh, I didn't try others.
-- glen
[That's one of the many, many bugs in csh. In posix shells such as
sh and bash, they do what you'd expect:
if [ 1 \> 2 ]; then echo true > file; fi # doesn't create the file
if [ 1 \> 2 ]; then echo true; fi > file # does create it
-John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.