Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-30-2010
Registered User
 
Join Date: Mar 2010
Posts: 124
Thanks: 21
Thanked 0 Times in 0 Posts
execute command stored in a string

Hi,

Here's the problem I am facing.
This is just an example:


Code:
 
list_files.ksh
------------
dir=$1
match=$2
 
var="ls $dir | grep $match"
files=`"$var"`

I get the below error on executing the above script:

Code:
./list_files.ksh[5]: ls /home/my_files | grep xml: not found

I know I am doing something very silly. Can you please tell me?

-dips
Sponsored Links
    #2  
Old 06-30-2010
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,146
Thanks: 3
Thanked 957 Times in 936 Posts

Code:
files=`eval "$var"`

The Following User Says Thank You to bartus11 For This Useful Post:
sujoydc (05-11-2012)
Sponsored Links
    #3  
Old 06-30-2010
Registered User
 
Join Date: Mar 2010
Posts: 124
Thanks: 21
Thanked 0 Times in 0 Posts
Hi bartus11,

Thanks it worked!

-dips
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to execute the stored procedure from shell script dineshmurs Shell Programming and Scripting 2 04-18-2010 01:53 AM
How to use a stored string in function call madhaviece Shell Programming and Scripting 1 09-16-2008 01:52 AM
How to build a command into a string rather than execute the command littlejon Shell Programming and Scripting 1 05-29-2008 08:05 PM
how to get the string stored in a variable in a line??? jisha Shell Programming and Scripting 4 04-05-2008 12:50 PM
Execute an Oracle stored procedure from a shell scrip mh53j_fe Shell Programming and Scripting 1 06-03-2005 03:17 PM



All times are GMT -4. The time now is 10:03 AM.