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 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> 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 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]