Register
It is currently Sun Jul 27, 2014 10:14 pm

cmd1 | RUN_IF_STDIN cmd2


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon Oct 13, 2008 11:33 am   

Joined: Mon Oct 13, 2008 11:20 am
Posts: 2
Code:
cmd1 | RUN_IF_STDIN cmd2

Is there any command RUN_IF_STDIN that runs cmd2 only if cmd1 outputs something to stdout? cmd1's stdout shoud be piped into cmd2's stdin.


Top
 Profile  
 PostPosted: Mon Oct 13, 2008 1:40 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
Code:
cmd1
if [ ! $? -eq 0 ]; then
cmd2
fi


$? points output of prior command.
hope it helps.


Top
 Profile  
 PostPosted: Mon Oct 13, 2008 3:42 pm   

Joined: Mon Oct 13, 2008 11:20 am
Posts: 2
1. $? refers to cmd1 return value... not to stdout.
2. cmd1's stdout should be piped to cmd2's stdin.


Top
 Profile  
 PostPosted: Wed Oct 15, 2008 12:22 am   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
well i dont know cmd1 return type; i estimate its char.

Code:
cmd=`cmd1`;if [ `echo $cmd | wc -c` -gt 1 ]; then echo $cmd | cmd2; fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP