KSH variable containing piped commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH variable containing piped commands
# 1  
Old 01-02-2010
KSH variable containing piped commands

Hi,
I am trying to execute a bunch of piped command which are stored in a variable, but only one command executed at a time, and rest of the pipes, commands and their arguments are considered as argument to the very first command.
Can you please help me in this?

Code:
bash-2.05$ cat test.sh
#!/usr/bin/ksh
xyz="ls -lrt | wc -l"
echo $($xyz)
bash-2.05$ ./test.sh
|: No such file or directory
wc: No such file or directory
-l: No such file or directory

bash-2.05$


-- Prashant.
# 2  
Old 01-02-2010
Quote:
Originally Posted by prashant.ladha
Code:
#!/usr/bin/ksh
xyz="ls -lrt | wc -l"
echo $($xyz)

Code:
xyz=$(ls -lrt | wc -l) # Use on of both statements 
xyz=`ls -lrt | wc -l` # with $() or `` (backticks)
echo $xyz

If you really want to use a string
Code:
xyz="ls -lrt | wc -l"
eval "$xyz"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable unexpectedly blank after piped loop

Hi, I was trying out a new way to parse multiple lines from a variable. I liked the "while read" method, so I used echo to pipe the variable into the while loop, the basic structure looking like: echo $var | while read nextline do a=blah done echo $a # it is empty! I... (8 Replies)
Discussion started by: ajhlinuxuser
8 Replies

2. Shell Programming and Scripting

Use cut output as variable piped awk command

Hi, I would like use the output of my cut command as a variable in my following awk command. Here's what I've written. cut -f1 info.txt | awk -v i=xargs -F'' '{if($6 == $i) print $20}' summary.txt Where obviously the 'xargs' doesn't do what I want. How can I pass my cut result to my awk... (3 Replies)
Discussion started by: heyooo
3 Replies

3. UNIX for Dummies Questions & Answers

ksh with Oracle commands

works fine. echo "Deleting CHOPOne Coreaccess from LAUA..." $ORACLE_HOME/bin/sqlplus username/password@servername << ! delete from usergrpdtl where username='acker'; commit; ! but not working with "if statement" even $TMPDIR/adlogin.log exists and greater than 0. if then ... (9 Replies)
Discussion started by: lawsongeek
9 Replies

4. Shell Programming and Scripting

Trouble executing piped shell commands in perl code

I am trying to execute a piped combination of shell commands inside a perl program. However, it is not working as desired. This is my program, i am trying to print only filenames from the output of ls -l $ cat list_test #!/usr/bin/perl -w use strict; my $count=0; my @list=`ls -l|awk... (4 Replies)
Discussion started by: sam05121988
4 Replies

5. UNIX for Dummies Questions & Answers

How to run multiple piped commands in a find -exec statement?

I can't get this to work. Running a single command works fine: find . -name "*.dat" -exec wc -l '{}' \; gives me the file name and number of lines in each .dat file in the directory. But what if I want to pipe commands, e.g. to grep something and get the number of lines with that pattern... (3 Replies)
Discussion started by: DJR
3 Replies

6. UNIX for Dummies Questions & Answers

Calling commands with ksh

Hi, I am not able to run below command on linux, it however works on solaris. If anyone knows the reason and a solution for it can you please let me know ? Linux ----- $> ksh 'echo hi' ksh: echo hi: No such file or directory $> which ksh /usr/bin/ksh Solaris ------ $> ksh 'echo... (2 Replies)
Discussion started by: krishnaux
2 Replies

7. UNIX for Advanced & Expert Users

Better KSH commands

Are there any documents available for checking the execution time taken by ksh commands? My requirement is to fine tune a set of shell scripts having lot of "echos" and "date"s. Is there a better replacement for the below code?. echo "ABC process started on `date`" some code.. echo... (12 Replies)
Discussion started by: engineer
12 Replies

8. UNIX for Dummies Questions & Answers

ksh substring commands

I am trying to get various portions of strings in my script, but am getting a substitution error. I followed the syntax that was described when I goggled this, but I can't get anything to work. #! /bin/ksh/ hello="adklafk;afak" #hello=${hello:3} hello=${$hello:3} happy="hey" echo... (1 Reply)
Discussion started by: anderssl
1 Replies

9. Shell Programming and Scripting

ksh GUI commands

I have a few scripts that i would like to make into GUI's. Are there scripting commands to make GUI's if so where can i get the list of commands and what they do or if anyone has an example of it. Anything will help, thanks (1 Reply)
Discussion started by: daltonkf
1 Replies

10. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies
Login or Register to Ask a Question