execute command stored in a string | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

execute command stored in a string

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-30-2010
dips_ag dips_ag is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 18 April 2013, 3:12 AM EDT
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
bartus11 bartus11 is online now Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 22 July 2014, 3:21 PM EDT
Posts: 3,707
Thanks: 7
Thanked 1,141 Times in 1,112 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
dips_ag dips_ag is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 18 April 2013, 3:12 AM EDT
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 03:34 PM.