From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII 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-11 08:47:38 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!bigfeed2.bellsouth.net!bigfeed.bellsouth.net!news.bellsouth.net!peer01.cox.net!cox.net!news-hub.cableinet.net!blueyonder!proxad.net!feeder2-1.proxad.net!news3-1.free.fr!not-for-mail Newsgroups: comp.unix.shell,comp.unix.tru64 From: Stephane CHAZELAS Subject: Re: Unexpected result from grep References: Mail-Copies-To: nobody Date: Thu, 11 Dec 2003 17:47:23 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit User-Agent: slrn/0.9.8.0 (Linux) Organization: Guest of ProXad - France NNTP-Posting-Date: 11 Dec 2003 17:47:38 MET NNTP-Posting-Host: 62.147.74.133 X-Trace: 1071161258 news3-1.free.fr 7137 62.147.74.133:1247 X-Complaints-To: abuse@proxad.net Xref: archiver1.google.com comp.unix.shell:3319 comp.unix.tru64:11027 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 ) -- St�phane ["Stephane.Chazelas" at "free.fr"]