Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Strange escaped < > behaviour

> "Jerry Rocteur" wrote:
>> We have a bunch of scripts that work on KSH and PDKSH like this:
>>echo '        ULOGPFX        = "<WORK_DIR>/ULOG"' | sed 's/.*\<\(.*\)\>.*/\1/'
>> Don't ask me why the escaped the < and > above but the scripts have been like
>>  this for a LONG LONG time!
>> Now with ZSH I get this behaviour
>>echo '        ULOGPFX        = "<WORK_DIR>/ULOG"' | sed 's/.*\<\(.*\)\>.*/\1/'
> (This is basically the same answer as Matt just gave but I'll send it
> anyway since I put in slightly different detail.)
> There's nothing in zsh that could possibly make a difference, and in
> bash on my system it gives me ULOG too.  This is because "\<" and "\>"
> in certain versions of sed (in particular GNU) match the start and end
> of a word.  See the "Regex syntax clashes" section in the "Reporting
> bugs" node of the GNU sed manual.
> I strongly suspect it's either calling a different version of sed, or
> some environment variable is changing the behaviour.  I can't see any
> environment variable relevant to GNU sed, however:  there's some mention
> of POSIXLY_CORRECT in the manual, but it didn't seem to have an effect
> in this case.
> If you want to avoid this generally, you do need to remove the
> backslashes from before the "<" and ">", in which case they are
> guaranteed not to do anything special.

Thanks Peter and Matt!!!

Indeed, I tried it on PDKSH with GNU sed and it works the same as on ZSH and BASH now that I've tested it.

You both hit the nail right on the head!

This has absolutely nothing to do with ZSH. I tested the script on HP UX with ksh and didn't check where sed was
coming from.

You guys know your tools, personally I always use perl even in one liners and it is a long time ago that I played with
sed so it didn't ring a bell.

Thanks again very much,


Messages sorted by: Reverse Date, Date, Thread, Author