This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CR-LF handling behavior of SED changed recently - this breaks a lot of MinGW cross build scripts

On 2017-06-09 10:09, Soegtrop, Michael wrote:
>> One could try making a wrapper shell script where sed usually
>> lives that adds those options and calls the real sed...
> I tried to do exactly this, but I tried to pipe a dos2unix command
> in between. It got a bit complicated because I had to parse the sed
> command line arguments. The solution of adding an extra command with
> -e is much more elegant. And you are right, replacing sed with a
> shell script is better than using an alias.

There is one issue here with sed, complicating simple aliasing or
substitution, requiring a shell function or script be used in the
general case.

If -e is used, then any inline script argument must be preceded by -e.

A simple alias, requiring an inline script argument, would have to be:
	alias sed='sed -es/\\r\$// -e'.

A shell function or script has to examine arguments to see if they are
options and if they have arguments, and whether any option is -e,
--expression or -f, --file.
Options and their arguments are skipped, and if -[ef] is not seen, the
next argument is an inline script, and must be preceded by -e.

For portable and safe scripts, explicit use of -e before inline script
arguments, and -- to end options, before input files, is recommended for
that reason.
And for makefiles, use SED, and default SED=sed or /bin/sed if not defined.

> But the -e method won't work for grep and for awk not in all cases.

Then you have to explicitly use tr, sed, or d2u/dos2unix to pre-process
Windows input or post-process Windows output.

Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]