- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: pipe or xargs
Operating System - Linux
1748092
Members
5840
Online
108758
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2008 03:52 AM
тАО12-30-2008 03:52 AM
echo -e "/usr\n/opt\n/bin" > file.txt
1, cat file.txt |ls (doesnt work, this 'ls' will list only the contents of pwd, but doesnt list the output from 'file.txt')
2, cat file.txt |xargs ls (this works, i.e ls will list the out of 'file.txt')
"pipe" pick the output of from the command on left, and make that output as an input to the command on right ?
then why "1" doesnt work as I expect(or as "2" works )
e.g
3, echo 123 | mail -s "testing" root@localhost (it works)
in this case(3), pipe is working as the definition, or simply the same as case "2"
please help/explain
Regards
1, cat file.txt |ls (doesnt work, this 'ls' will list only the contents of pwd, but doesnt list the output from 'file.txt')
2, cat file.txt |xargs ls (this works, i.e ls will list the out of 'file.txt')
"pipe" pick the output of from the command on left, and make that output as an input to the command on right ?
then why "1" doesnt work as I expect(or as "2" works )
e.g
3, echo 123 | mail -s "testing" root@localhost (it works)
in this case(3), pipe is working as the definition, or simply the same as case "2"
please help/explain
Regards
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2008 04:45 AM
тАО12-30-2008 04:45 AM
Solution
>1) cat file.txt | ls
ls(1) doesn't take its input from stdin, only from command line args. With a real shell (posix/ksh) you can do:
ls $(< file.txt )
>2) cat file.txt | xargs ls (this works
Yes, xargs reads stdin and then invokes ls with command line args.
>"pipe" pick the output of from the command on left, and make that output as an input to the command on right?
Yes but there is no need to use evil cat(1) in your simple cases:
xargs ls < file.txt
>then why "1" doesn't work as I expect
Because "ls < file.txt" doesn't read stdin.
>3) echo 123 | mail -s "testing" root@localhost (it works)
>pipe is working as the definition
The echo/pipe works because mail reads from stdin and has command line options.
ls(1) doesn't take its input from stdin, only from command line args. With a real shell (posix/ksh) you can do:
ls $(< file.txt )
>2) cat file.txt | xargs ls (this works
Yes, xargs reads stdin and then invokes ls with command line args.
>"pipe" pick the output of from the command on left, and make that output as an input to the command on right?
Yes but there is no need to use evil cat(1) in your simple cases:
xargs ls < file.txt
>then why "1" doesn't work as I expect
Because "ls < file.txt" doesn't read stdin.
>3) echo 123 | mail -s "testing" root@localhost (it works)
>pipe is working as the definition
The echo/pipe works because mail reads from stdin and has command line options.
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2008 10:19 AM
тАО12-30-2008 10:19 AM
Re: pipe or xargs
>"pipe" pick the output of from the command on left, and make that output as an input to the command on right?
output and input here refer to the stdout and stdin respectively, stdin is not same as command line args.
If a program uses commandline args u have to use xargs.
If your program works on the input suplied on stdin; a | will be sufficient.
-Sri
output and input here refer to the stdout and stdin respectively, stdin is not same as command line args.
If a program uses commandline args u have to use xargs.
If your program works on the input suplied on stdin; a | will be sufficient.
-Sri
abandon all hope, ye who enter here..
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP