From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25071 invoked from network); 13 Jan 2005 20:51:43 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 13 Jan 2005 20:51:43 -0000 Received: (qmail 45581 invoked from network); 13 Jan 2005 20:51:35 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 13 Jan 2005 20:51:35 -0000 Received: (qmail 9938 invoked by alias); 13 Jan 2005 20:51:25 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8370 Received: (qmail 9919 invoked from network); 13 Jan 2005 20:51:24 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 13 Jan 2005 20:51:24 -0000 Received: (qmail 44065 invoked from network); 13 Jan 2005 20:50:25 -0000 Received: from unknown (HELO vrs.michael-prokop.at) (81.223.126.153) by a.mx.sunsite.dk with SMTP; 13 Jan 2005 20:50:20 -0000 Received: from localhost (unknown [81.223.126.153]) by vrs.michael-prokop.at (Postfix) with ESMTP id CB75610410 for ; Thu, 13 Jan 2005 21:50:19 +0100 (CET) Date: Thu, 13 Jan 2005 21:50:18 +0100 From: Michael Prokop To: Zsh users list Subject: egrep with zsh as /bin/sh - wordsplitting Message-ID: <2005-01-13T17-30-35@devnull.michael-prokop.at> Reply-To: Michael Prokop Mail-Followup-To: Zsh users list Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-URL: http://www.michael-prokop.at/ X-Operating-System: Debian GNU/Linux - 2.6.8.1 on a i686 X-Registered-Linux-User: 224337 X-Crypto: GnuPG/1.2.3 http://www.gnupg.org X-GPG-Key-ID: 0x37E272E8 X-GPG-Key: http://www.michael-prokop.at/gpg X-GPG-Fingerprint: 04AE E62C 9502 CD34 A7DA 857B D8DF 53FB 37E2 72E8 User-Agent: Mutt/1.5.6+20041219i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=0.1 required=6.0 tests=FORGED_RCVD_HELO autolearn=ham version=3.0.2 X-Spam-Hits: 0.1 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/