bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: Bug in Win32 port of sed


From: Eli Zaretskii
Subject: Re: Bug in Win32 port of sed
Date: Sat, 03 Nov 2007 20:39:13 +0200

> Date: Sat, 03 Nov 2007 16:33:21 +0100
> From: Martin Schulze <address@hidden>
> Cc: address@hidden, address@hidden
> 
> 2. Execute the following command from within cmd.exe shell to filter the 
> quotation marks:
> 
> sed s!\"!!g file
> 
> where file is the name of the test file you used.
> 
> This will give the expected output on the screen. But as soon as you try to 
> redirect or pipe the output, you will get errors:
> 
> sed s!\"!!g file >anyfile
> 
> The above command fails:
> 
> sed: can't read >anyfile: Invalid argument

I think this has nothing to do with Sed per se.  It's an issue with
quoting and how the Windows shell handles it.

Note that your command line has an unpaired quote.  The backslash does
not escape it, not in the Windows shell, because the Windows shell
does not treat backslashes as escape characters.  So you are playing
with fire when you use such a command line: in some cases the Windows
shell is evidently able to recover from unterminated quoted string,
while in others it cannot.  In particular, it thinks the > redirection
character is being quoted, so it complains about a non-existent file
`>anyfile'.

There really isn't a good way of passing a quote to a program on
Windows, due to subtly incompatible ways the shell and the wildcard
expansion code in the Windows programs treat quoting.  One way that
should work, but not always does (it does work in this case) is to use
the ^ character to escape the quote:

  sed s!\^"!!g sedt.txt >anyfile

Or put the redirection _before_ anything else in the command line:

   >anyfile sed s!\"!!g file

(yes, this is a perfectly valid command line).  Or use some port of a
Unixy shell, where you should be able to use '...' and the backslashes
to quote any character.

> BTW, there is a GNU sed v3.02.80 alpha release floating around that does NOT 
> have this bug. This one is explicitely claimed to be buggy on Eric's site but 
> at least it's working fine for me at least in this case. I downloaded the 
> precompiled DOS version by Eli Zaretskii from Eric's mirror site:
> http://www.student.northpark.edu/pemente/sed/sed3028a.zip
> 
> The test case with redirect executes just fine without any errors with this 
> alpha version.

Thanks for the credit, but I think the explanation here is that the
DOS (a.k.a, DJGPP) port of Sed is invoked by Windows through a
different shell (command.com vs cmd.exe), which has slightly different
behavior wrt unpaired quotes.  The DJGPP port also uses a very
different method of expanding quotes it gets from the shell, so that
might be another reason.  FWIW, I have here a DJGPP port of Sed 4.1.4,
and it also works with your original command, so it's not only the
v3.02.80 that does.




reply via email to

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