Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: "Chris F.A. Johnson" <c.fa.johnson@rogers.com>
Subject: Re: Unexpected result from grep
Date: 11 Dec 2003 16:37:17 GMT	[thread overview]
Message-ID: <bra6fs$12s89$1@ID-210011.news.uni-berlin.de> (raw)
In-Reply-To: ffb05a35.0312110813.6e4e57ba@posting.google.com

On Thu, 11 Dec 2003 at 16:13 GMT, Dan wrote:
> Hello,
> 
> I can't seem to figure out why this isn't working.  I'm running it on
> Tru64 V5.1A with patch kit 5.  I'm probably missing something obvious.
> :-(
> 
> Here is my script:
> /tmp # cat search
> #!/usr/bin/ksh
> set -x
> 
> typeset -r COMMAND='/sbin/grep'

    grep is in sbin???

> typeset -r EXPRESSION="${1}"
> typeset -r CHECK_FILE="${2}"
> typeset    RESULT=''
> 
> RESULT="$(${COMMAND} -E \'${EXPRESSION}\' ${CHECK_FILE} 2>/dev/null)"
> 
> print "RESULT: ${RESULT}"
> 
> Here is the test file:
> /tmp # cat afile
> rsh

   Now try it with afile containing (literally):

'rsh'

> Here is what happens when I run the script:
> /tmp # search rsh afile
> + typeset -r COMMAND=/sbin/grep
> + typeset -r EXPRESSION=rsh
> + typeset -r CHECK_FILE=afile
> + typeset RESULT=
> + + /sbin/grep -E 'rsh' afile
> + 2> /dev/null
> RESULT=
> + print RESULT:
> RESULT:
> 
> Yet if I run the command at the command line, I get this:
> /tmp # /sbin/grep -E 'rsh' afile
> rsh

   But your script is:

/sbin/grep -E \'rsh\' afile

   It searched for rsh enclosed in single quotes.

   What you want is:

RESULT=$(${COMMAND} -E "${EXPRESSION}" "${CHECK_FILE}" 2>/dev/null)


-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


  parent reply	other threads:[~2003-12-11 16:37 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 [this message]
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
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