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: Barry Margolin Newsgroups: comp.compilers,comp.unix.shell,comp.os.linux.misc Subject: Re: magic/absurd bash interpreter/compiler ? Date: Fri, 28 Dec 2012 10:25:33 -0500 Organization: A noiseless patient Spider Lines: 38 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <12-12-029@comp.compilers> References: <12-12-014@comp.compilers> <12-12-018@comp.compilers> <12-12-020@comp.compilers> <12-12-021@comp.compilers> <12-12-025@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1356817759 93644 64.57.183.58 (29 Dec 2012 21:49:19 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 29 Dec 2012 21:49:19 +0000 (UTC) Keywords: design, history, comment Posted-Date: 29 Dec 2012 16:49:19 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:813 comp.unix.shell:6271 comp.os.linux.misc:6918 glen herrmannsfeldt wrote: > In comp.compilers Eric 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]