niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
ksh parsing question
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
Rakesh Sharma
*nix forums beginner


Joined: 28 Feb 2005
Posts: 36

PostPosted: Tue Feb 15, 2005 9:54 am    Post subject: Re: ksh parsing question Reply with quote

"Tom Shippee" <t.s.shippee@snet.net> wrote in message news:

Quote:

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?


eval does exactly that, it parses your string one more time before executing.

eval "$CMD"
Back to top
TB
*nix forums Guru Wannabe


Joined: 14 Mar 2005
Posts: 241

PostPosted: Tue Feb 15, 2005 3:28 am    Post subject: Re: ksh parsing question Reply with quote

Instead of using the double quotes ( " ) use the grave accent ( ` ),
not the single quote, but the ` that is usually with the ~ on your
keyboard.

T.
Back to top
Tom Shippee
*nix forums beginner


Joined: 29 Mar 2005
Posts: 2

PostPosted: Tue Feb 15, 2005 2:50 am    Post subject: ksh parsing question Reply with quote

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]
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 11:14 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Newbie question: How to forward a domain to a mailbox? leei Postfix 0 Fri Aug 24, 2007 4:55 pm
No new posts configuration question for httpd Karl Wang Apache 1 Fri Jul 21, 2006 2:10 pm
No new posts nim problem/question Ron AIX 0 Fri Jul 21, 2006 1:57 pm
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am
No new posts Encryption Question dtuttle1@gmail.com Berkeley DB 2 Thu Jul 20, 2006 10:09 pm

Debt Consolidation | Loans | Just Holden Commodores | Credit Counseling | Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1924s ][ Queries: 20 (0.1211s) ][ GZIP on - Debug on ]