LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-27-2012, 12:11 PM   #1
telebabbo
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
[BASH] How to get command name of piped output


I have:
Code:
echo "one two three test" | myprogram
and I want 'myprogram' to return (or store into variable):
- "one two three test"
- "echo"

Any ideas?
 
Old 05-27-2012, 12:26 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
Try this:
Code:
program="echo"
echo "$program one two three four" | myprogram
Then, in "myprogram", strip off the first word and store into desired variable
 
Old 05-27-2012, 12:54 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
As pixellany did show, there is no way to retrieve the name of the command that generated the piped standard input (unless you explicitly write it down) since the program is invoked after the standard input is generated and every information about the generator is lost.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SCO Unix - Capture output from tar that is piped through FTP BaDm00n Other *NIX 2 04-10-2010 02:12 PM
How to redirect stderr from piped output? redss Programming 2 08-21-2009 04:50 PM
Automatically append another piped command to issued command in bash amateen Programming 1 05-07-2009 07:36 AM
bash: piped loop in same shell Vit77 Programming 2 04-30-2009 03:50 AM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 03:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration