* Strange escaped < > behaviour
@ 2009-03-11 8:22 Jerry Rocteur
2009-03-11 9:50 ` Matt Wozniski
2009-03-11 9:56 ` Peter Stephenson
0 siblings, 2 replies; 4+ messages in thread
From: Jerry Rocteur @ 2009-03-11 8:22 UTC (permalink / raw)
To: zsh-users
Hi,
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
The easy way to fix it is to remove the back slash in front of the < and >
However this is VERY annoying.
Why does the above give us ULOG and why does this differ from the KSH and PDKSH.
Can someone please help me see why ..
Thanks,
Jerry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Strange escaped < > behaviour
2009-03-11 8:22 Strange escaped < > behaviour Jerry Rocteur
@ 2009-03-11 9:50 ` Matt Wozniski
2009-03-11 9:56 ` Peter Stephenson
1 sibling, 0 replies; 4+ messages in thread
From: Matt Wozniski @ 2009-03-11 9:50 UTC (permalink / raw)
To: Jerry Rocteur, zsh-users
On Wed, Mar 11, 2009 at 4:22 AM, Jerry Rocteur wrote:
> Hi,
>
> 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
>
> The easy way to fix it is to remove the back slash in front of the < and >
>
> However this is VERY annoying.
>
> Why does the above give us ULOG and why does this differ from the KSH and PDKSH.
I'm going to go *way* out on a limb with my assumptions here, but,
here goes: You're clearly doing this on a non-linux unix, since Linux
would use gnu sed, where \< and \> are special and different from <
and >. If you were on Linux, your script would never have worked.
So, my huge assumption would be to guess that you probably put paths
to gnu versions of tools in your path. I know I did the last time I
was stuck using Solaris. So, my best guess is that your $PATH is set
differently on zsh than in ksh or pdksh, causing zsh to call a version
of sed where \< and \> match word boundaries, instead of matching <
and >. Change your $PATH, or use an absolute path to the sed binary
that works with pdksh, and I'm guessing things will just work.
~Matt
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Strange escaped < > behaviour
2009-03-11 8:22 Strange escaped < > behaviour Jerry Rocteur
2009-03-11 9:50 ` Matt Wozniski
@ 2009-03-11 9:56 ` Peter Stephenson
2009-03-11 10:46 ` Jerry Rocteur
1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2009-03-11 9:56 UTC (permalink / raw)
To: zsh-users
"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.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Strange escaped < > behaviour
2009-03-11 9:56 ` Peter Stephenson
@ 2009-03-11 10:46 ` Jerry Rocteur
0 siblings, 0 replies; 4+ messages in thread
From: Jerry Rocteur @ 2009-03-11 10:46 UTC (permalink / raw)
To: Peter Stephenson, godlygeek; +Cc: zsh-users
> "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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-11 10:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-11 8:22 Strange escaped < > behaviour Jerry Rocteur
2009-03-11 9:50 ` Matt Wozniski
2009-03-11 9:56 ` Peter Stephenson
2009-03-11 10:46 ` Jerry Rocteur
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).