ksh parsing question
From: Tom Shippee (t.s.shippee_at_snet.net)
Date: 02/15/05
- Next message: TB: "Sorting only certain data in file."
- Previous message: William Park: "Re: convert to uppercase or lowercase"
- Next in thread: TB: "Re: ksh parsing question"
- Reply: TB: "Re: ksh parsing question"
- Reply: rakesh sharma: "Re: ksh parsing question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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]
- Next message: TB: "Sorting only certain data in file."
- Previous message: William Park: "Re: convert to uppercase or lowercase"
- Next in thread: TB: "Re: ksh parsing question"
- Reply: TB: "Re: ksh parsing question"
- Reply: rakesh sharma: "Re: ksh parsing question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|