execute command stored in a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting execute command stored in a string
# 1  
Old 06-30-2010
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
# 2  
Old 06-30-2010
Code:
files=`eval "$var"`

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 06-30-2010
Hi bartus11,

Thanks it worked!

-dips
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep a sub-string from a string stored in a variable.

For example: I am grepping "Hello" from a file and there are 10 matches. So all ten lines with match will get stored into a variable($match). Now I want to ignore those lines which have "Hi" present in that. Currently I tried this: match = grep "Hello" file | grep -v "Hi" file But that's not... (2 Replies)
Discussion started by: pavan
2 Replies

2. Shell Programming and Scripting

Searching a string stored in other file

I need to design a script which can do the following: I have two files abc.txt and constant.hmtl abc.txt contains some 5 string that I need to see if they exist in contants.html. Constants.hmtl is a very large file around 800 lines. I want to search all the strings present in file... (8 Replies)
Discussion started by: hemasid
8 Replies

3. Shell Programming and Scripting

Unable to execute Stored Procedure from CRON

Hi, I am very new to this environment - I hope this is the right platform to discuss my issue: I created a CRON job to run a Stored Procedure from our database - Sybase. Within the Stored Procedure there is a TRUNCATE table and CREATE table function. the CRON job fails to run with... (2 Replies)
Discussion started by: pizzazzz
2 Replies

4. Shell Programming and Scripting

KSH to execute stored procs/ctrl files

I am needing to call sqlplus and sqlldr in the same korn shell script. Below are the steps that I need to accomplish. I am new to Oracle shell scripting so an example would be great. CBOB_LOAD.KSH - script name Calls Oracle stored procedure sp_CBOB_CLEAR_LN_STAGING (SERVER: TESTSVR100) Calls... (0 Replies)
Discussion started by: acewilli
0 Replies

5. Shell Programming and Scripting

Execute stored procedure through script in sybase database and store the output in a .csv file

Hi, I have a sybase stored procedure which takes two input parameters (start_date and end_date) and when it get executed, it gives few records as an output. I want to write a unix script (ksh) which login to the sybase database, then execute this stored procedure (takes the input parameter as... (8 Replies)
Discussion started by: amit.mathur08
8 Replies

6. Shell Programming and Scripting

How to execute the stored procedure from shell script

How to execute the stored procedure from shell script and is there any possibility to print the dbms output in a log file. (2 Replies)
Discussion started by: dineshmurs
2 Replies

7. Shell Programming and Scripting

How to use a stored string in function call

Hi All I have written code for storing data in a string based on pattern. whenever i tried to use in a function call its not getting there. Actually the same logic was applied for another string..then i can use the string at any function. the code goes like this /mp metadata/{... (1 Reply)
Discussion started by: madhaviece
1 Replies

8. Shell Programming and Scripting

How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example: mycmd='' if ...; then $mycmd='sudo ' fi $mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile res=`$mycmd` (I'm also not sure of the best way to execute the command from the... (1 Reply)
Discussion started by: littlejon
1 Replies

9. Shell Programming and Scripting

how to get the string stored in a variable in a line???

Hi all, I want to search for a data type in a line.For this in a loop i am checking for $DATA_TYPE in a line using grep.But grep is not able to find when i give this. Can any one tell me how to check string in $DATA_TYPE variable in line usign grep (or) any other way to do the above task. ... (4 Replies)
Discussion started by: jisha
4 Replies

10. Shell Programming and Scripting

Execute an Oracle stored procedure from a shell scrip

Here is a snippet of my code: if then echo "\n Deleting all reports older than 24 hours. \n" >> $logfile ls -l $FileName >> $logfile ... (1 Reply)
Discussion started by: mh53j_fe
1 Replies
Login or Register to Ask a Question