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

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

Re: sed bug?


From: Bob Proulx
Subject: Re: sed bug?
Date: Sun, 19 Feb 2012 11:15:28 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

Pierre Gaston wrote:
> Scott Hall wrote:
> > If I include quotes around the input path (which I need if there is a
> > space in the path), it results in an "Invalid Argument" error.
> >
> > example:
> > sed -f x.sed "..\test files\*.txt"
> > sed: can't read ..\test files\*.txt: Invalid argument
> 
> sed isn't the one doing the expansion of *.txt to a list of filenames, it
> is your shell. Then when sed runs it sees a list of filenames passed as
> arguement.
> 
> If you put *.txt   inside quotes you tell the shell not to expand this list
> and sed receives a literal *.txt that it can't interpret.

And so we come to the problem of how to make it work.  Which is a
problem because sed is a GNU/Unix utility which was ported to MS and
the two worlds have quite different behaviors.

You didn't say what command shell you were using?  Hopefully you *are*
using one because it is apparent that your port of sed requires it.
Which means you need to quote the space but do not quote the *.  Which
also tells me that you probably need to use the normal type of
directory separators, forward slashes not back slashes, too.  Really
only the space needs to be quoted.  But it is typical to quote the
longest string that encompasses everything that needs quoting.

Try this:

  sed -f x.sed "../test files/"*.txt

If that doesn't work then you also need to get a Unix shell too.  Head
over to http://www.cygwin.com/ and grab a shell too.

More information that you may need as background:

The GNU and Unix shell expands file glob wildcards and hands the
expanded list to the program.  The MS command interpreter (can't
really call it a shell) does not.  The MS command interpreter passes
the *.txt argument directly to the program the program is expected to
expand it.  This is related to a very short limit (IIRC 128 characters
or something close to that limit) for command line arguments in MS
systems.

So.  What does that mean?  It means that when programs are ported to
MS the author doing the software port must make a decision.  They need
to decide should they include code to expand arguments or not?
Sometimes people who port code decide to do it one way.  Sometimes
they decide to do it another way.  Someone ported the version of sed
you are using.  What do they say on the matter?  You should ask them.
Because GNU is not Unix and it also isn't MS either.  :-)

However the *.txt didn't get expanded by the program.  So I that means
that the person who did the port expected it to be exactly like the
GNU/Unix version.  Meaning that it is wanting a GNU/Unix like command
line shell to expand those wildcards.

In which case you are running only HALF of the required programs to
make this work for you.  You need the OTHER half of them which is a
shell to go along with it.  Therefore my reasoning is that you need a
shell and you need to run sed from the shell and have the shell expand
the file glob wildcards and pass it to the shell as intended.  Which
means you need to use normal style forward slashes and not MS style
backward slashes because a Unix shell will expect backslashes to be
used for character quoting.

Bob



reply via email to

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