From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1012a6,f7f68e18cfb8d31b X-Google-Attributes: gid1012a6,public X-Google-Thread: fa528,f7f68e18cfb8d31b X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2003-12-12 05:19:27 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: daniel.j.botz@cummins.com (Dan) Newsgroups: comp.unix.shell,comp.unix.tru64 Subject: Re: Unexpected result from grep Date: 12 Dec 2003 05:19:27 -0800 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 192.158.61.141 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1071235167 3492 127.0.0.1 (12 Dec 2003 13:19:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 12 Dec 2003 13:19:27 +0000 (UTC) Xref: archiver1.google.com comp.unix.shell:3356 comp.unix.tru64:11032 Joseph Dionne wrote in message news:... > 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