LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 01-11-2007, 03:41 PM   #1
amdGTintel
LQ Newbie
 
Registered: Dec 2006
Posts: 5

Rep: Reputation: 0
Higher scripting using |, <,> and `


Hello.
I would like to know information about |, <, > , and ` in bash scripting,
redriecting direction, what side is input what is output.

can you point me / tell me what I need to know??

Thanks!
 
Old 01-11-2007, 04:00 PM   #2
lord-fu
Member
 
Registered: Apr 2005
Location: Ohio
Distribution: Slackware && freeBSD
Posts: 676

Rep: Reputation: 30
"|" is a pipe whatever is on the left will be piped out to the right.
Small example ps aux | grep httpd

"<" and ">" offer kind of the same thing. One is an output ">" the other an input "<".

cat file > filecontents.txt or cat file >> filecontents.txt The second would concat on the contents of file into filecontents.txt

some commmand here < file would run a command but pull its input from the file file.

Sorry I am not the most 1337 when it comes to this, but thats the general skinny. Sorry if I am wrong on any of the above. Hope it helps.
 
Old 01-11-2007, 04:02 PM   #3
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
| This is called a pipe. It connects the standard output of the program on the left with the standard input of the program on the right.

< This redirects input to come from somewhere else besides standard input. So if you do something like this: "wc -l < somefile", wc will take input from somefile.

> This redirects output away from /dev/stdout to wherever you specify. So if you do this: "ls > file.lst", ls's output will go to the file file.lst instead of the terminal screen.

` When surrounding a command, this substitutes the output of the command for this part of the current command line. So if you do something like this: "echo There are `ls | wc -l` files in the current directory", the shell will first run "ls | wc -l" and substitute the output of this command for everything beginning with ` and ending with ` in the current command line. Then, after this substitution is made the current command line will be run. If there are 30 files in the current directory when this command is run, then this is what the command line will look like after the substitution is made: "echo There are 30 files in the current directory".

http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

Here is a tutorial to get you started.
 
Old 01-12-2007, 04:05 AM   #4
amdGTintel
LQ Newbie
 
Registered: Dec 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by penguiniator
| This is called a pipe. It connects the standard output of the program on the left with the standard input of the program on the right.

< This redirects input to come from somewhere else besides standard input. So if you do something like this: "wc -l < somefile", wc will take input from somefile.

> This redirects output away from /dev/stdout to wherever you specify. So if you do this: "ls > file.lst", ls's output will go to the file file.lst instead of the terminal screen.

` When surrounding a command, this substitutes the output of the command for this part of the current command line. So if you do something like this: "echo There are `ls | wc -l` files in the current directory", the shell will first run "ls | wc -l" and substitute the output of this command for everything beginning with ` and ending with ` in the current command line. Then, after this substitution is made the current command line will be run. If there are 30 files in the current directory when this command is run, then this is what the command line will look like after the substitution is made: "echo There are 30 files in the current directory".

http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

Here is a tutorial to get you started.

Thanks and what does
|| do??!

Thanks!
 
Old 01-12-2007, 04:23 AM   #5
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
|| is logical or.
 
Old 01-12-2007, 10:04 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
And && is logical AND.
Typically, || and && are used in if-statements, to combine multiple conditions.
A quick example:
Code:
nrSongs=`ls -1 *.[Mm][Pp]3 | wc -l`; 
#the above statement executes the "ls" command, passes it's output to "wc" utility for counting the lines
#and stores the result (number of lines) in the variable $nrSongs
if (( $nrSongs > 0 )) && (( $mySum < 11 )); then
  echo "There are between 1 and 10 songs in the current directory `pwd`.";
fi;
`` are called backticks. They run a command and capture it's output, for instance for substitution into a string or command (like in amdGIntel's post) or for saving it into a variable (like in example above).
Please distinguish them clearly from '' (single quotes) and "" (double quotes), which all have distinct meanings to the shell.

For more info, read up on quoting, pipes, IO redirection and stuff like that in "man bash" (or the man page of your shell, if you're not using bash).
 
  


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
Can't get a higher resolution. duffmckagan Yoper 3 04-28-2007 01:00 PM
FC4 or higher? storpappa Linux - Newbie 1 12-07-2006 08:10 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
Higher Resolution muppski Linux - General 7 11-30-2005 05:46 AM
Need higher resolution 1madstork Debian 2 11-25-2004 03:50 AM


All times are GMT -5. The time now is 12:46 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