LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-29-2005, 02:24 AM   #1
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Rep: Reputation: 16
Difference between "<" and "|" in shell


What's the difference between using "<" and "|" when combining bash shell commands? Don't both refer to stdin, the only difference being the order? And couldn't you just enter something directly into a command rather than using both of the above? For example:

$ ls < pwd

and

$ pwd | ls

and

$ ls pwd

Does anybody know how to clearly explain the difference between all these different stdin things, and what the conceptual differences between "<" and "|" are? I'm totally new to this...

Thanks a lot!
 
Old 03-29-2005, 02:40 AM   #2
Orkie
Member
 
Registered: Mar 2005
Distribution: Breezy Badger
Posts: 248

Rep: Reputation: 30
Not sure about the <.
In your 2nd example, you are taking the output of pwd and passing it to ls (e.g. if you wanted to save the output of ls, you do "ls | tee ls.log"). On the 3rd one, you are passing "pwd" as an arugment to ls. If there is a file called 'pwd' in the current working directory, then ls will display it.
 
Old 03-29-2005, 04:01 AM   #3
mschutte
Member
 
Registered: Jan 2005
Location: Innsbruck, Austria
Distribution: Debian GNU/Linux Lenny
Posts: 68

Rep: Reputation: 15
The three ways to run ls are completely different:

1. '<' writes the content of a FILE to the standard input of a program. Most programs behave like if you typed the content of the file manually (except programs which use a library for controlling a tty, like ncurses).

2. '|' is the pipe operator. It feeds the standard output of the left-hand side PROGRAM to the program on the right-hand side.

3. Here you pass an argument to ls.
 
Old 03-29-2005, 10:39 AM   #4
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Original Poster
Rep: Reputation: 16
Thanks for the replies.

mschutte, so for the second case would you say it's passing the stdout of the program on the left to the STDIN of the program on the right?
 
Old 03-29-2005, 12:43 PM   #5
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
Quote:
Originally posted by veeruk101
Thanks for the replies.

mschutte, so for the second case would you say it's passing the stdout of the program on the left to the STDIN of the program on the right?
Exactly. As mschutte pointed out, this is known as "piping".

Also sometimes you will see something like:

# echo 'hello' >> /home/user/somefile.txt

Two >'s signify an append to the text file. If you use one > it will delete existing information in the file.
 
  


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
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 05:08 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Can you explain the difference between "Free Software (GNU)" and "Open Source"? vharishankar General 5 03-03-2005 10:40 AM
difference between "Web server local URL" and "IPv4 address"? kpachopoulos Linux - General 2 09-17-2004 02:30 PM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 02:42 AM


All times are GMT -5. The time now is 10:22 AM.

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