Re: Unexpected result from grep

From: Jens Schweikhardt (usenet_at_schweikhardt.net)
Date: 12/11/03


Date: 11 Dec 2003 16:32:50 GMT

In comp.unix.shell Dan <daniel.j.botz@cummins.com> 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'
# typeset -r EXPRESSION="${1}"
# typeset -r CHECK_FILE="${2}"
# typeset RESULT=''
#
# RESULT="$(${COMMAND} -E \'${EXPRESSION}\' ${CHECK_FILE} 2>/dev/null)"

For EXPRESSION=foo, this will grep for 'foo', *including* the single
quotes. You need to eval the string to have the single quotes be
interpreted.

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

Should do the trick.

Regards,

        Jens

-- 
Jens Schweikhardt  http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)


Relevant Pages

  • Re: Unexpected result from grep
    ... In comp.unix.shell Dan wrote: ... # Here is my script: ... # typeset -r COMMAND='/sbin/grep' ... You need to eval the string to have the single quotes be ...
    (comp.unix.shell)
  • Re: Self-removing temp files
    ... > typeset -i numtemp i ... > typeset -xf mktemp ... the EXIT trap in the function is executed when the ... > function call ends and not when the calling script ends. ...
    (comp.unix.shell)
  • Re: move to upper case
    ... :> Rob Bradford wrote: ... :>> The script takes one parameter that should be three characters at max. ... There is no 'typeset' in the POSIX shell specification. ...
    (comp.unix.shell)
  • Re: move to upper case
    ... The script takes one parameter that should be three characters at max. ... There is no 'typeset' in the POSIX shell specification. ...
    (comp.unix.shell)
  • typeset in Korn Shell scripts
    ... Except for two people who suggested calling 'typeset' by its full path (can't be ... typeset in Korn Shell scripts ... I have a Korn script that uses ... the 'typeset -l' command to translate a value into lower case. ...
    (SunManagers)