autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bourne sh redirection, a loop variable, and ':'


From: Ralf Wildenhues
Subject: Re: Bourne sh redirection, a loop variable, and ':'
Date: Sat, 13 Sep 2008 09:27:14 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

[ moving from autoconf@ ]

Hi Bruce,

* Bruce Korb wrote on Wed, Sep 03, 2008 at 10:29:01PM CEST:
> On Wed, Sep 3, 2008 at 12:45 PM, Ralf Wildenhues <address@hidden> wrote:
> > is this nice little Bourne shell quirk already known?
> >
> > $ for i in 1 2 3 ; do : >x$i; done
> > $ ls
> > x1
> >
> > It works when I use 'echo' instead of ':'.
> >
> > Seen with Solaris 10 sh, but also some other old shells IIRC.
> 
> Are there any shells around older than a Solaris /bin/sh ??
> Over 20 years old, IIRC.  Anyway, for amusement:
> 
> #  for i in 1 2 3 ; do : >x$i ; sleep 60 ; done ; date ; ls -l x*
> Wednesday, September  3, 2008  1:25:25 PM PDT
> -rw-r--r--   1 root     root           0 Sep  3 13:22 x1
> 
> it seems that the no-op is removed from the loop after the first iteration.
> I guessed as much, but this makes it clearer.  Pretty weird. - Bruce

Indeed.  OK to install this patch to describe the issue?

Thanks,
Ralf

commit 0b2a5f07e6b283b70e1a5c2d17eb5e7ad870ad7b
Author: Ralf Wildenhues <address@hidden>
Date:   Sat Sep 13 09:25:38 2008 +0200

    Mention Solaris sh ':' redirection bug.
    
    * doc/autoconf.texi (File Descriptors): Redirecting ':'
    in a loop causes bogus optimization with Solaris sh.

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 76bf746..14be3b5 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -13003,6 +13003,18 @@ File Descriptors
 @samp{matter} and @file{void} being empty.  However, this bug is
 probably not of practical concern to modern platforms.
 
+Solaris 10 @command{sh} will try to optimize away a @command{:} command
+in a loop, even if it is redirected:
+
address@hidden
+$ @kbd{for i in 1 2 3 ; do : >x$i; done}
+$ @kbd{ls}
+x1
address@hidden example
+
address@hidden
+As a workaround, @command{echo} or @command{eval} can be used.
+
 Don't rely on file descriptors 0, 1, and 2 remaining closed in a
 subsidiary program.  If any of these descriptors is closed, the
 operating system may open an unspecified file for the descriptor in the




reply via email to

[Prev in Thread] Current Thread [Next in Thread]