Store a command and execute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store a command and execute
# 1  
Old 07-10-2012
Store a command and execute

Hi All,

I am trying to get latest folders based on some condition. The below sample script working fine for me.
Code:
#!/bin/sh 
INSTALLDIR=`pwd`
_UPGRADE_=1
CMD="ls -rtp $INSTALLDIR | grep /"
CMD1="ls -rtp $INSTALLDIR | grep / | grep -v '^server/$'"
 
Get_my_dir(){
   for SDIR in $(ls -rtp $INSTALLDIR | grep /) ; do
   echo source dir : $SDIR
   done
}
 
Get_my_dir

But when i modified the line
Code:
for SDIR in $(ls -rtp $INSTALLDIR | grep /) ; do

to
Code:
for SDIR in $( $CMD) ; do

This gives error. I want prepare my command and store into $CMD variable based on the boolean variable for _UPGRADE_.

Please let me know, how to run the $CMD insist of the hard coded things.

Thanks in advance.

Last edited by Scrutinizer; 07-10-2012 at 07:00 AM.. Reason: code tags instead of quote tags
# 2  
Old 07-10-2012
Code:
for SDIR in $(eval $CMD); do echo ....; done

This User Gave Thanks to ygemici For This Post:
# 3  
Old 07-10-2012
Thanks a lot ygemici
# 4  
Old 07-24-2012
Code:
for SDIR in $(eval $CMD); do echo ....; done

This syntax working fine in Redhat Linux.
But it not working in Solaris. Any one Please suggest the equal command in Solaris
# 5  
Old 07-24-2012
Solaris uses a mouldy old pre-posix shell which doesn't support $( )

Either use the ksh shell Solaris also comes with, or use ` `
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Execute sequential files and store data in single file

1)In a particualr path i have a set of inputfiles like path:/defaultmis/MonthlyLoads/INFA_EXPORT_022013/map* example: 1)map_de 2)map_cod 3)map_feg ........and so on in above path there wil be nearly 15 to 20 files starting with map and in other path i have another file input file... (4 Replies)
Discussion started by: katakamvivek
4 Replies

3. Shell Programming and Scripting

Different cmd to execute and based on some pattern parse it and then store result in xlx format

Hi I have a different requirement, I need to run some application on my device from a file app_name.txt one by one which is like this: /usr/apps/email /usr/apps/message /usr/apps/settings after each app while it is running I need to execute again one cmd like ps -ef |grep... (2 Replies)
Discussion started by: Sanjeev Roy
2 Replies

4. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

5. Shell Programming and Scripting

How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files. all my parameters files are in the same directory, so pick them up with ls *.para >>dirafter that I have a dir file like that: param1.para param2.para etc... I... (2 Replies)
Discussion started by: shadok
2 Replies

6. 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

7. Shell Programming and Scripting

Shell Linux to connect to a database and execute store procedure

HI, i want to write a script (Linux) that: 1) connect to a database oracle 2) execute some store procedure. Can anybody help me, please? Thanks a lot Andrew (3 Replies)
Discussion started by: manichino74
3 Replies

8. Shell Programming and Scripting

To store output of ls command

Hi, I need to pass a run time input to unix script which tracks the list of files in the directory under certain pattern. The files which are matched to the given pattern then need to be stored in the array. Requesint you all to please suggest me the solution. I gave the below command in the... (13 Replies)
Discussion started by: Sekar1
13 Replies

9. UNIX for Dummies Questions & Answers

execute store procedure

Hi, can someone point out the tutorial or syntax for how to execute store procedure through shell scripting . thanks. (7 Replies)
Discussion started by: epall
7 Replies

10. UNIX for Dummies Questions & Answers

Plz Help : How to use write command to execute command on some other terminal

Hi Group , I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages. - i m writing >write user-id ! ls o ctrl-d inspite of executing the command ls,other terminal shows ! ls. Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies
Login or Register to Ask a Question