zsh-users
 help / color / mirror / code / Atom feed
From: Michael Prokop <news@michael-prokop.at>
To: Zsh users list <zsh-users@sunsite.dk>
Subject: egrep with zsh as /bin/sh - wordsplitting
Date: Thu, 13 Jan 2005 21:50:18 +0100	[thread overview]
Message-ID: <2005-01-13T17-30-35@devnull.michael-prokop.at> (raw)

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/


             reply	other threads:[~2005-01-13 20:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-13 20:50 Michael Prokop [this message]
2005-01-13 21:23 ` Danek Duvall
2005-01-14  8:43 ` Stephane Chazelas
2005-01-14 17:15   ` Michael Prokop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2005-01-13T17-30-35@devnull.michael-prokop.at \
    --to=news@michael-prokop.at \
    --cc=zsh-users@sunsite.dk \
    --cc=zsh@michael-prokop.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).