zsh-users
 help / color / mirror / code / Atom feed
* egrep with zsh as /bin/sh - wordsplitting
@ 2005-01-13 20:50 Michael Prokop
  2005-01-13 21:23 ` Danek Duvall
  2005-01-14  8:43 ` Stephane Chazelas
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Prokop @ 2005-01-13 20:50 UTC (permalink / raw)
  To: Zsh users list

Hello,

I'm maintainer of a Linux Live-CD with zsh as it's default shell.
/bin/sh is pointing to /bin/zsh.

I've a problem with the scripts egrep and fgrep.
That's the original egrep-script:

,---- [ /bin/egrep - original version ]
| #!/bin/sh
| exec grep -E ${1+"$@"}
`----

egrep in scripts (for example in 'translate') which use
'#!/bin/sh' as the shebang-line results in problems due to
wordsplitting.

I stumbled upon:
http://lists.gnu.org/archive/html/bug-gnu-utils/2002-04/msg00361.html
http://www.zsh.org/mla/workers//2002/msg00546.html

The solution would be to adjust egrep (and fgrep):

,---- [ /bin/egrep for zsh, not portable ]
| #!/bin/sh
| setopt noshwordsplit
| exec grep -E ${1+"$@"}
`----

or:

,---- [ /bin/egrep for zsh, portable? ]
| #!/bin/sh
| exec grep -E "$@"
`----

or:

,---- [ /bin/egrep for zsh, probably more portable? ]
| #!/bin/sh
| if test -n "${ZSH_VERSION+set}"; then
|   exec grep -E "$@"
| else
|   exec grep -E ${1+"$@"}
| fi
`----

Refering to Peter [1] the following works also in bash, but not with
sh on SunOS 5.8:

,---- [ /bin/egrep for zsh - with quotes]
| #!/bin/sh
| exec grep -E "${1+"$@"}"
`----

Why does the original egrep version use ${1+"$@"} and not
"$@" or "${1+"$@"}"? Which ones are shell-compatible?
Refering to [1] the ${1+"$@"}-version handles zero arguments
correctly. Which version should be prefered in general
(to be sh-compatible)?

Which of the above versions would you suggest to take for
egrep/fgrep? The last ("${1+"$@"}") one?

[1] http://www.zsh.org/mla/workers//2002/msg00544.html

thanks for any feedback && regards,
-mika-
-- 
 ,'"`.         http://www.michael-prokop.at/
(  grml.org -» Linux for texttool-users and sysadmins
 `._,          http://www.grml.org/


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-01-14 17:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-13 20:50 egrep with zsh as /bin/sh - wordsplitting Michael Prokop
2005-01-13 21:23 ` Danek Duvall
2005-01-14  8:43 ` Stephane Chazelas
2005-01-14 17:15   ` Michael Prokop

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).