1

Sometimes we use pipe symbol for mathematical expression, sometimes we use for execute two or more command at time,but what this actually is ? What is the main use of this symbol in script ?

Mastan
  • 492
  • 2
  • 5
  • 13
  • What mathematical expression usage are you talking about? – Etan Reisner Mar 16 '15 at 18:55
  • Of course, a symbol may be have different meanings in different contexts... What is your question, exactly? – jub0bs Mar 16 '15 at 18:56
  • @EtanReisner, bitwise OR, I'm presuming? – Charles Duffy Mar 16 '15 at 19:01
  • @CharlesDuffy I was assuming the OP meant in a shell context but I suppose it might have been a broader one (though that makes the question a bit less sensible). – Etan Reisner Mar 16 '15 at 19:08
  • @EtanReisner, bitwise-ORs are certainly possible in a math context in shell. But, yes, I'm inclined to call this answer too broad regardless. (We certainly don't want to be overrun by questions of the form "what are all the uses of ${THIS_CHARACTER} in ${THIS_LANGUAGE}?"). – Charles Duffy Mar 16 '15 at 19:08
  • @CharlesDuffy Indeed. I just find it hard to believe (though not impossible) that those two uses occurred in equivalent enough amounts to make the "main purpose" confusing. – Etan Reisner Mar 16 '15 at 19:10
  • if we want to add two float value then we should use pipe symbol,,The the mathematical expression @etanResiner – Mastan Mar 16 '15 at 19:12
  • @LungiPoraMastan, pardon? Bash doesn't support native floating-point math at all. – Charles Duffy Mar 16 '15 at 19:14
  • I wonder if http://stackoverflow.com/questions/9834086/what-is-a-simple-explanation-for-how-pipes-work-in-bash might be considered a duplicate – Charles Duffy Mar 16 '15 at 19:15
  • # a=6.5;b=9.8;
    # echo "$a + $b" | bc
    16.3
    i think those are floating value.. @CharlesDuffy
    – Mastan Mar 16 '15 at 19:22
  • @Mastan, indeed, but that's math being done by `bc`, not by `bash`. `bc` is an external tool, not part of the shell. – Charles Duffy Mar 16 '15 at 19:27
  • opps..i am sorry..actually i am new in stackoverflow and shell scripting.. Can u refer me a book which is good and easy for learn shell script for beginner ? @CharlesDuffy – Mastan Mar 16 '15 at 19:29
  • http://mywiki.wooledge.org/BashGuide is a good place to start -- actively maintained by people who care deeply about accuracy. A published dead-tree book, I don't have any good recommendations on. – Charles Duffy Mar 16 '15 at 19:30
  • On a related point, BashFAQ #22 -- http://mywiki.wooledge.org/BashFAQ/022 -- is somewhat related to the question of doing floating-point in bash. – Charles Duffy Mar 16 '15 at 19:31

1 Answers1

0

The pipe lets you direct the output of one command into another command. That is the stdout of the command on the left hand side becomes the stdin of the command on the right hand side. You can then chain commands together to make a script (or as I like to call it, an uber command). This is very powerful stuff and is quite fun to do. For example, during the Wordlcup I tasked myself with finding out the score of the Brazil match just using my command line. I was able to pipe commands together till and get my answer. Started with a "curl http://sports.yahoo.com" and piped the output to a combination of grep and awk commands.

Jose Martinez
  • 11,452
  • 7
  • 53
  • 68