ksh parsing question

From: Tom Shippee (t.s.shippee_at_snet.net)
Date: 02/15/05


Date: Tue, 15 Feb 2005 03:50:53 GMT

I am writing a program to read a text file, parse it, and run commands
based on one of the fields. The "single" commands work ok, but ksh appears
not to parse the variable line when it is executed. If there is a pipe in
the string the command gets an error. For example, below the first sequence
fails, but the other two work ok. Any suggestions on how to get ksh to
parse the text string before executing?

( I am able to get around this by creating a temporary file with the CMD
string then executing it. I also tried creating an "alias" then executing
that. This works ok, but it seems like there should be a more elegant way to
manage this little problem. The goal is to have a script that wil work on
AIX, Solaris and HPUX. Any suggestion appreciated. )

#!/bin/ksh

#

#

# Does Not Work

#

CMD="netstat -an | grep LIST"

echo "Command1: $CMD"

$CMD

#

# Works OK

#

CMD="netstat -an"

$CMD

#
# Works OK
#

netstat -an | grep LIST

Error OutPut:

$ /tmp/temp1.sh

Command1: netstat -an | grep LIST

netstat: extra arguments

usage: netstat [-anv] [-f address_family]

       netstat [-g | -p | -s] [-n] [-f address_family] [-P protocol]

       netstat -m

       netstat -i [-I interface] [-an] [-f address_family] [interval]

       netstat -r [-anv] [-f address_family]

       netstat -M [-ns] [-f address_family]

       netstat -D [-I interface] [-f address_family]



Relevant Pages

  • Re: ksh parsing question
    ... > I am writing a program to read a text file, parse it, and run commands ... > not to parse the variable line when it is executed. ... > the string the command gets an error. ... it parses your string one more time before executing. ...
    (comp.unix.shell)
  • Re: Searching for Robust Download Automation
    ... to execute a command upon successful transfer. ... ad hoc methods for detecting corrupted/incomplete files, executing ... those commands, and cleaning out the transferred files. ... UUCP has done the things I list above for 20+ years, ...
    (comp.unix.shell)
  • Makeinfo error when attempting to compile binutils-2.18 for AVR target
    ... I'm trying to compile the gnu avr toolchain on Fedora 7. ... config.status: executing depfiles commands ...
    (Fedora)
  • Re: remove user exe execute permission
    ... The only way I can think of to prevent a user from executing commands is to ... needs to be able to call CreateProcess* to successfully run CGI Scripts on ... >> full control under their IIS web folder to their files. ...
    (microsoft.public.windows.server.security)
  • Re: source question
    ... > currently executing using the 'info script' command. ... some main commands ... some filea commands ...
    (comp.lang.tcl)