bug-make
[Top][All Lists]
Advanced

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

Re: [PATCH] Bad sed expression in bootstrap.bat


From: Eli Zaretskii
Subject: Re: [PATCH] Bad sed expression in bootstrap.bat
Date: Sun, 25 Dec 2022 19:20:01 +0200

> From: Paul Smith <psmith@gnu.org>
> Cc: bug-make@gnu.org
> Date: Sun, 25 Dec 2022 09:06:53 -0500
> 
> On Sun, 2022-12-25 at 02:29 +0100, Giangiacomo Zaffini wrote:
> > I cannot see where
> > sed -e "s/$/ \\/"
> > can be wrong on Windows command line or Windows PowerShell.
> 
> It's because, apparently, cmd.exe sees the "\\" and turns it into a
> single "\" before it invokes the command.  Then the syntax is:
> 
>   sed -e 's/$/ \/'
> 
> which is not legal because the backslash escapes the trailing slash,
> and now there's no trailing slash for the s/// operator.  So you get an
> error.
> 
> If I'm in cmd.exe and I use Perl to show how cmd.exe will interpret the
> command line (using Perl because I know it will be installed if someone
> is running the GNU make test suite; you could use something else if you
> like):
> 
>   C:\Users\user> perl -e "print $ARGV[0];" "s/$/ \\/"
>   s/$/ \/
> 
> note how there's only one "\" here which is wrong and gives an error

Not that it matters much for the purposes of this discussion, but it
is not cmd.exe that does this, it is the startup code of the program
which processes the command line and breaks it into argv[] elements.
The specific function which does that is part of the Microsoft runtime
library.

And one other nit: the working of that function in the Microsoft
runtime has changed between XP and newer systems.  On XP, the original
command, viz.:

  sed -e "s/$/ \\/"

yields the expected "s/$/ \\/" argv element; the backslash is not
eaten.  I see this both in Perl and in a simple C program I have which
just prints its argv[].  So this command will work differently
depending on which version of Windows it runs, and therefore I would
suggest to replace it with something that doesn't need to double or
triple backslashes, in order for it to be more portable.

Btw, what is the purpose of the bootstrap.bat file?  It is not part of
the Make source tarball, so who and when uses it?



reply via email to

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