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


Groups > comp.compilers > #809

Re: magic/absurd bash interpreter/compiler ?

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 2012-12-28 03:17 +0000
Organization Aioe.org NNTP Server
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>

Cross-posted to 3 groups.

Show all headers | 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