Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: "Dan Mercer" <dmercer@mn.rr.com>
Subject: Re: Unexpected result from grep
Date: Sat, 20 Dec 2003 16:13:48 GMT	[thread overview]
Message-ID: <0z_Eb.170955$Eq1.160079@twister.rdc-kc.rr.com> (raw)
In-Reply-To: brvm26$ef0$1@jeeves.eng.abbnm.com


"Peter da Silva" <peter@abbnm.com> wrote in message news:brvm26$ef0$1@jeeves.eng.abbnm.com...
: My biennial lament about excessive use of non-portable shell syntax:
:
: In article <DD2Cb.62750$%h4.33767@twister.tampabay.rr.com>,
: Joseph Dionne  <no@emailplease.org> wrote:
: > I have noticed that the Tru64 version of ksh is not a true Korn shell.
:
: Doesn't matter if it is or not, {grep \'$var\' ..} is not going to produce
: the intended result. It looks like the result of copying something from
: a vaguely similar-looking script that was doing something completely
: different, rather than actually working out what you need to do.
:
: The whole script is excessively complex. Even assuming you want to
: parameterise the grep command, this would do precisely the same thing:
:
:     COMMAND=/sbin/grep
:
:     RESULT="`"$COMMAND" -E "$1" "$2" 2>/dev/null`"
:
: And it would work in any bourne-based shell, and unless typeset is
: doing something particularly clever with the following line, it
: avoids a potential security problem related to the re-evaluation of
: the second argument.
:
: > >>typeset -r CHECK_FILE="${2}"
:
: As would any of following, of course, but they're not as portable:
:
: > > RESULT=$(
: > >   "${EGREP[@]}" -- "$EXPRESSION" "$CHECK_FILE" 2> /dev/null
: > > )
: > >
: > > or
: > >
: > > COMMAND='/sbin/grep -E -- "$EXPRESSION" "$CHECK_FILE" 2> /dev/null'
: > > RESULT=$(eval "$COMMAND")
: > >
: > > GREP=/sbin/grep
: > > RESULT=$(
: > >   "$GREP" -E -- "$EXPRESSION" "$CHECK_FILE" 2> /dev/null
: > > )
:
: Basically, when I get an installer or other script that starts with
: something like
:
: #!/bin/ksh
:
: or
:
: #!/bin/bash
:
: I find it falls into one of these categories:
:
: 1. It actually needs some functionality that isn't available
:    in generic sh. - 1%
:
: 2. It is actually portable "sh" code and just needs the "#!"
:    line fixed. - 9%
:
: 3. It uses post-sh functionality, but doesn't actually need
:    it. - 90%
:
: I wish people would pay attention to code portability in shell scripts.
: It's not that hard, and it does pay off.

Portability using a minimal sh functionality pushes the burden of portability
from the shell to the OS.  You then must rely the portability of shell
utilities like awk (which may actualy be old awk) or perl (which may
not be installed or may be perl 4) or sed or find (gnu find has some
significant incompatibilities with SysV find).  Even the shell known as
"sh" may have some significant incompatibilities - it may be influenced
by the ENV variable (many "posix" shells),  it may source ~/.shrc
(NCR SysVR3 sh) - it may or may not accept options to echo.

It is much easier to code for portable ksh - or,  failing that,  provide
your own shell like Oracle does with osh.

Even the location of sh is problematic - HP-UX puts it in /usr/bin
and symbolically links /usr/bin to /bin - but calls that a "transitional link"
indicating that users should prepare for a time when /bin does not
exist at all.

It's too bad the POSIX shell group did such a poor job - too much
infighting from people with vested interests.  Personally,  I would
have been perfectly happy had they just said : "We're going to use
zsh - get over it."

Dan Mercer
:
: --
: I've seen things you people can't imagine. Chimneysweeps on fire over the roofs
: of London. I've watched kite-strings glitter in the sun at Hyde Park Gate.  All
: these things will be lost in time, like chalk-paintings in the rain.   `-_-'
: Time for your nap.  | Peter da Silva | Har du kramat din varg, idag?    'U`




  reply	other threads:[~2003-12-20 16:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-11 16:13 Unexpected result from grep Dan
2003-12-11 16:32 ` Jens Schweikhardt
2003-12-11 16:37 ` Chris F.A. Johnson
2003-12-11 16:47 ` Stephane CHAZELAS
2003-12-11 18:24   ` Joseph Dionne
2003-12-12 13:19     ` Dan
2003-12-19 20:11     ` Peter da Silva
2003-12-20 16:13       ` Dan Mercer [this message]
2003-12-22 21:14         ` Peter da Silva
2003-12-23 16:01           ` Dan Mercer
2003-12-23 21:01             ` Peter da Silva
2003-12-23 22:15               ` Dan Mercer
2003-12-25 22:29                 ` Peter da Silva
2003-12-24 16:41       ` Stephane CHAZELAS
2003-12-25 22:15         ` Peter da Silva
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox