Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Strange escaped < > behaviour
- X-seq: zsh-users 13898
- From: "Jerry Rocteur" <jerry@xxxxxxx>
- To: "Peter Stephenson" <pws@xxxxxxx>, godlygeek@xxxxxxxxx
- Subject: Re: Strange escaped < > behaviour
- Date: Wed, 11 Mar 2009 11:46:15 +0100 (CET)
- Cc: zsh-users@xxxxxxxxxx
- Importance: Normal
- In-reply-to: <200903110956.n2B9u8Ip018799@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <57016.153.98.68.197.1236759758.squirrel@xxxxxxxxxxxxxxxxxxx> <200903110956.n2B9u8Ip018799@xxxxxxxxxxxxxx>
> "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/'
>> WORK_DIR
>>
>> 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/'
>> ULOG
>
> (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,
Jerry
Messages sorted by:
Reverse Date,
Date,
Thread,
Author