Re: magic/absurd bash interpreter/compiler ?

Barry Margolin <barmar@alum.mit.edu>
Fri, 28 Dec 2012 10:25:33 -0500

          From comp.compilers

Related articles
[2 earlier articles]
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)
| List of all articles for this month |
From: Barry Margolin <barmar@alum.mit.edu>
Newsgroups: comp.compilers,comp.unix.shell,comp.os.linux.misc
Date: Fri, 28 Dec 2012 10:25:33 -0500
Organization: A noiseless patient Spider
References: 12-12-014 12-12-018 12-12-020 12-12-021 12-12-025
Keywords: design, history, comment
Posted-Date: 29 Dec 2012 16:49:19 EST

glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
> 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]


csh is so broken, it's best ignored when talking about "Unix shells" in
general. Even more so when someone says "many Unix shells", since one
exception hardly counts as "many".


--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
[Several other people wrote to agree that csh is bad news. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.