Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-27-2007, 10:34 PM   #1
Registered: Mar 2003
Posts: 178

Rep: Reputation: 30
Is there a variable that represents data passed in a pipe

With find you have the special {} variable which represents data returned from find. This data can be passed to another command called from find. Now with a pipe you can pipe input to another command but what happens with commands that need a value given like cp? For example, I can't use ls | cp newlocation since I don't have something to specify for the input (I know this is a useless command it's just a quick example). Is there a way like ls | cp {} newlocation?
Old 02-27-2007, 11:01 PM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Look at the xargs command. It allows you to use the output of one command as arguments of the other command. For commands like mv, you will need to use an argument such as -t/--target-directory, so that the destination can appear first on the command line.

The xargs command can also be used with the find command instead of -exec command '{}' \;
The advantage of doing this is because you can limit the size of the arguments handled at once. The argument list size can cause find to fail if used with -exec. The same is true for using wild cards to produce arguments to "for" if there are too many matching filenames.

In a related subject, some commands that normally take filenames can take input from a stream instead by using a hyphen as an argument. For example: man topic -t | kghostview -

To copy the output of a stream to a file, use "> filename" or ">> filename" depending on whether you want to create a new file or append to the end of a file.


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
Pipe inside variable isn't working in bash Reginald0 Linux - General 6 12-09-2015 09:56 AM
how to pipe/redirect awk output into a variable? johnpaulodonnell Linux - Newbie 2 01-25-2007 06:54 AM
creating c programs to accpet data from a pipe - '|' schneidz Programming 9 11-21-2006 09:16 AM
sed not working if value is passed thru a variable containg value suchi_s Programming 7 10-29-2004 07:41 AM
Broken pipe error when sending data on LAN Tanc Linux - Networking 2 09-14-2003 05:16 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:33 PM.

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