LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 11:11 AM   #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, 11:26 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 11:54 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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



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 01:12 PM
How to redirect stderr from piped output? redss Programming 2 08-21-2009 03:50 PM
Automatically append another piped command to issued command in bash amateen Programming 1 05-07-2009 06:36 AM
bash: piped loop in same shell Vit77 Programming 2 04-30-2009 02:50 AM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 02:07 PM

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

All times are GMT -5. The time now is 06:30 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
Open Source Consulting | Domain Registration