From: daniel.j.botz@cummins.com (Dan)
Subject: Re: Unexpected result from grep
Date: 12 Dec 2003 05:19:27 -0800 [thread overview]
Message-ID: <ffb05a35.0312120519.ad792dc@posting.google.com> (raw)
In-Reply-To: DD2Cb.62750$%h4.33767@twister.tampabay.rr.com
Joseph Dionne <jdionne@hotmail.com> wrote in message news:<DD2Cb.62750$%h4.33767@twister.tampabay.rr.com>...
> I have noticed that the Tru64 version of ksh is not a true Korn shell.
> Is the source code available. Has anyone else noticed any differences?
>
> Stephane CHAZELAS wrote:
> > 2003-12-11, 08:13(-08), Dan:
> > [...]
> >
> >>typeset -r COMMAND='/sbin/grep'
> >
> >
> > a command is either a simple command that can be represented as
> > a list of arguments, so with an *array* type variable, or a more
> > complex one, that needs to be a string to be evaluated though
> > the "eval" builtin. or a very very simple command that only
> > consists of one 0th arg, in which case you can use a string, but
> > you should rather name that variable PROG_PATH or even GREP_PATH
> > or GREP as it appears that you need a grep-like program.
> >
> >
> >>typeset -r EXPRESSION="${1}"
> >>typeset -r CHECK_FILE="${2}"
> >>typeset RESULT=''
> >>
> >>RESULT="$(${COMMAND} -E \'${EXPRESSION}\' ${CHECK_FILE} 2>/dev/null)"
> >
> >
> > Once a variable is left unquoted, word splitting and filename
> > generation is performed, that's not what you want. Moreover,
> > even if '$EXPRESSION' is a single word that expands to no
> > filename, that will seach for 'the-expression' (with the single
> > quotes), not the-expression.
> >
> >
> > set -A EGREP /sbin/grep -E
> > 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
> > )
> >
> >
Thanks everyone for your help! The "eval" certainly does the trick.
Shortly after I posted the question, I figured it out by trial and
error. But with your responses, I now know the why.
Thanks again!!
Dan
next prev parent reply other threads:[~2003-12-12 13:19 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 [this message]
2003-12-19 20:11 ` Peter da Silva
2003-12-20 16:13 ` Dan Mercer
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