From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,f7f68e18cfb8d31b X-Google-Attributes: gidfa528,public X-Google-Thread: 1012a6,f7f68e18cfb8d31b X-Google-Attributes: gid1012a6,public X-Google-ArrivalTime: 2003-12-11 08:37:19 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!cpe0030ab04dde2-cm023459906638.cpe.net.cable.rogers.COM!not-for-mail From: "Chris F.A. Johnson" Newsgroups: comp.unix.shell,comp.unix.tru64 Subject: Re: Unexpected result from grep Followup-To: comp.unix.shell Date: 11 Dec 2003 16:37:17 GMT Message-ID: References: NNTP-Posting-Host: cpe0030ab04dde2-cm023459906638.cpe.net.cable.rogers.com (24.156.50.72) X-Trace: news.uni-berlin.de 1071160637 1143049 24.156.50.72 ([210011]) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.unix.shell:3314 comp.unix.tru64:11025 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