Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #809

Re: magic/absurd bash interpreter/compiler ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end
From glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups comp.compilers, comp.unix.shell, comp.os.linux.misc
Subject Re: magic/absurd bash interpreter/compiler ?
Date Fri, 28 Dec 2012 03:17:42 +0000 (UTC)
Organization Aioe.org NNTP Server
Lines 28
Sender johnl@iecc.com
Approved comp.compilers@iecc.com
Message-ID <12-12-025@comp.compilers> (permalink)
References <12-12-014@comp.compilers> <12-12-018@comp.compilers> <12-12-020@comp.compilers> <12-12-021@comp.compilers>
NNTP-Posting-Host news.iecc.com
X-Trace leila.iecc.com 1356708041 39506 64.57.183.58 (28 Dec 2012 15:20:41 GMT)
X-Complaints-To abuse@iecc.com
NNTP-Posting-Date Fri, 28 Dec 2012 15:20:41 +0000 (UTC)
Keywords history, design, comment
Posted-Date 28 Dec 2012 10:20:41 EST
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Xref csiph.com comp.compilers:809 comp.unix.shell:6269 comp.os.linux.misc:6908

Cross-posted to 3 groups.

Show key headers only | View raw


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]

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

magic/absurd bash interpreter/compiler ? Avoid9Pdf@gmail.com - 2012-12-23 11:04 +0000
  Re: magic/absurd bash interpreter/compiler ? J G Miller <miller@yoyo.ORG> - 2012-12-24 00:28 +0000
  Re: magic/absurd bash interpreter/compiler ? "Jonathan Thornburg" <jthorn@astro.indiana.edu> - 2012-12-24 03:57 +0000
  Re: magic/absurd bash interpreter/compiler ? Eric <eric@deptj.eu> - 2012-12-24 19:13 +0000
    Re: magic/absurd bash interpreter/compiler ? Barry Margolin <barmar@alum.mit.edu> - 2012-12-24 20:48 -0500
    Re: magic/absurd bash interpreter/compiler ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-25 03:25 +0000
      Re: magic/absurd bash interpreter/compiler ? Eric <eric@deptj.eu> - 2012-12-26 12:51 +0000
        Re: magic/absurd bash interpreter/compiler ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-28 03:17 +0000
          Re: magic/absurd bash interpreter/compiler ? Barry Margolin <barmar@alum.mit.edu> - 2012-12-28 10:25 -0500

csiph-web