cat and pipe vs. redirection [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
4













This question already has an answer here:



  • How is this command legal ? “> file1 < file2 cat”

    1 answer



What's the difference between these two commands?



cat /proc/uptime | awk 'print $1'



< /proc/uptime awk 'print $1'



Specifically, how does the second command work? Doesn't the redirection operator < has to be accompanied by a command? What does it mean to redirect the contents of a file like that?







share|improve this question














marked as duplicate by Kusalananda, SivaPrasath, Thomas Dickey, Jeff Schaller, Archemar Sep 3 at 13:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I came across it online and wanted to know how it worked.. there was no explanation backing the usage.
    – walksignison
    Sep 2 at 22:41











  • unix.stackexchange.com/questions/131775/…
    – walksignison
    Sep 2 at 23:20










  • @Goro I don't see anything wrong with the second command. What's wrong about it?
    – Joseph Sible
    Sep 2 at 23:24










  • @JosephSible can you please explain how it works?
    – walksignison
    Sep 2 at 23:27






  • 3




    Reading this comment from Stéphane made me smarter; thought I’d include it here.
    – Jeff Schaller
    Sep 2 at 23:33














up vote
6
down vote

favorite
4













This question already has an answer here:



  • How is this command legal ? “> file1 < file2 cat”

    1 answer



What's the difference between these two commands?



cat /proc/uptime | awk 'print $1'



< /proc/uptime awk 'print $1'



Specifically, how does the second command work? Doesn't the redirection operator < has to be accompanied by a command? What does it mean to redirect the contents of a file like that?







share|improve this question














marked as duplicate by Kusalananda, SivaPrasath, Thomas Dickey, Jeff Schaller, Archemar Sep 3 at 13:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I came across it online and wanted to know how it worked.. there was no explanation backing the usage.
    – walksignison
    Sep 2 at 22:41











  • unix.stackexchange.com/questions/131775/…
    – walksignison
    Sep 2 at 23:20










  • @Goro I don't see anything wrong with the second command. What's wrong about it?
    – Joseph Sible
    Sep 2 at 23:24










  • @JosephSible can you please explain how it works?
    – walksignison
    Sep 2 at 23:27






  • 3




    Reading this comment from Stéphane made me smarter; thought I’d include it here.
    – Jeff Schaller
    Sep 2 at 23:33












up vote
6
down vote

favorite
4









up vote
6
down vote

favorite
4






4






This question already has an answer here:



  • How is this command legal ? “> file1 < file2 cat”

    1 answer



What's the difference between these two commands?



cat /proc/uptime | awk 'print $1'



< /proc/uptime awk 'print $1'



Specifically, how does the second command work? Doesn't the redirection operator < has to be accompanied by a command? What does it mean to redirect the contents of a file like that?







share|improve this question















This question already has an answer here:



  • How is this command legal ? “> file1 < file2 cat”

    1 answer



What's the difference between these two commands?



cat /proc/uptime | awk 'print $1'



< /proc/uptime awk 'print $1'



Specifically, how does the second command work? Doesn't the redirection operator < has to be accompanied by a command? What does it mean to redirect the contents of a file like that?





This question already has an answer here:



  • How is this command legal ? “> file1 < file2 cat”

    1 answer









share|improve this question













share|improve this question




share|improve this question








edited Sep 2 at 23:27









Joseph Sible

676113




676113










asked Sep 2 at 22:38









walksignison

435




435




marked as duplicate by Kusalananda, SivaPrasath, Thomas Dickey, Jeff Schaller, Archemar Sep 3 at 13:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Kusalananda, SivaPrasath, Thomas Dickey, Jeff Schaller, Archemar Sep 3 at 13:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • I came across it online and wanted to know how it worked.. there was no explanation backing the usage.
    – walksignison
    Sep 2 at 22:41











  • unix.stackexchange.com/questions/131775/…
    – walksignison
    Sep 2 at 23:20










  • @Goro I don't see anything wrong with the second command. What's wrong about it?
    – Joseph Sible
    Sep 2 at 23:24










  • @JosephSible can you please explain how it works?
    – walksignison
    Sep 2 at 23:27






  • 3




    Reading this comment from Stéphane made me smarter; thought I’d include it here.
    – Jeff Schaller
    Sep 2 at 23:33
















  • I came across it online and wanted to know how it worked.. there was no explanation backing the usage.
    – walksignison
    Sep 2 at 22:41











  • unix.stackexchange.com/questions/131775/…
    – walksignison
    Sep 2 at 23:20










  • @Goro I don't see anything wrong with the second command. What's wrong about it?
    – Joseph Sible
    Sep 2 at 23:24










  • @JosephSible can you please explain how it works?
    – walksignison
    Sep 2 at 23:27






  • 3




    Reading this comment from Stéphane made me smarter; thought I’d include it here.
    – Jeff Schaller
    Sep 2 at 23:33















I came across it online and wanted to know how it worked.. there was no explanation backing the usage.
– walksignison
Sep 2 at 22:41





I came across it online and wanted to know how it worked.. there was no explanation backing the usage.
– walksignison
Sep 2 at 22:41













unix.stackexchange.com/questions/131775/…
– walksignison
Sep 2 at 23:20




unix.stackexchange.com/questions/131775/…
– walksignison
Sep 2 at 23:20












@Goro I don't see anything wrong with the second command. What's wrong about it?
– Joseph Sible
Sep 2 at 23:24




@Goro I don't see anything wrong with the second command. What's wrong about it?
– Joseph Sible
Sep 2 at 23:24












@JosephSible can you please explain how it works?
– walksignison
Sep 2 at 23:27




@JosephSible can you please explain how it works?
– walksignison
Sep 2 at 23:27




3




3




Reading this comment from Stéphane made me smarter; thought I’d include it here.
– Jeff Schaller
Sep 2 at 23:33




Reading this comment from Stéphane made me smarter; thought I’d include it here.
– Jeff Schaller
Sep 2 at 23:33










1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted










In general, foo < bar and < bar foo are equivalent in bash scripting. Any time < filename is processed by the shell, it means that the command it's associated with will have its standard input come from that file. No extra command or process is involved with this; the shell does it itself.



Running cat filename reads the contents of the specified file and writes them to standard output. | between two commands means connect standard output of the left command to standard input of the right command.



Thus, both of your commands have the same effect of sending the contents of /proc/uptime to awk, but the first way starts an extra cat process to do so.






share|improve this answer
















  • 1




    (warning: snark): see also UUOC
    – Anthony Sottile
    Sep 3 at 3:59

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
6
down vote



accepted










In general, foo < bar and < bar foo are equivalent in bash scripting. Any time < filename is processed by the shell, it means that the command it's associated with will have its standard input come from that file. No extra command or process is involved with this; the shell does it itself.



Running cat filename reads the contents of the specified file and writes them to standard output. | between two commands means connect standard output of the left command to standard input of the right command.



Thus, both of your commands have the same effect of sending the contents of /proc/uptime to awk, but the first way starts an extra cat process to do so.






share|improve this answer
















  • 1




    (warning: snark): see also UUOC
    – Anthony Sottile
    Sep 3 at 3:59














up vote
6
down vote



accepted










In general, foo < bar and < bar foo are equivalent in bash scripting. Any time < filename is processed by the shell, it means that the command it's associated with will have its standard input come from that file. No extra command or process is involved with this; the shell does it itself.



Running cat filename reads the contents of the specified file and writes them to standard output. | between two commands means connect standard output of the left command to standard input of the right command.



Thus, both of your commands have the same effect of sending the contents of /proc/uptime to awk, but the first way starts an extra cat process to do so.






share|improve this answer
















  • 1




    (warning: snark): see also UUOC
    – Anthony Sottile
    Sep 3 at 3:59












up vote
6
down vote



accepted







up vote
6
down vote



accepted






In general, foo < bar and < bar foo are equivalent in bash scripting. Any time < filename is processed by the shell, it means that the command it's associated with will have its standard input come from that file. No extra command or process is involved with this; the shell does it itself.



Running cat filename reads the contents of the specified file and writes them to standard output. | between two commands means connect standard output of the left command to standard input of the right command.



Thus, both of your commands have the same effect of sending the contents of /proc/uptime to awk, but the first way starts an extra cat process to do so.






share|improve this answer












In general, foo < bar and < bar foo are equivalent in bash scripting. Any time < filename is processed by the shell, it means that the command it's associated with will have its standard input come from that file. No extra command or process is involved with this; the shell does it itself.



Running cat filename reads the contents of the specified file and writes them to standard output. | between two commands means connect standard output of the left command to standard input of the right command.



Thus, both of your commands have the same effect of sending the contents of /proc/uptime to awk, but the first way starts an extra cat process to do so.







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 2 at 23:29









Joseph Sible

676113




676113







  • 1




    (warning: snark): see also UUOC
    – Anthony Sottile
    Sep 3 at 3:59












  • 1




    (warning: snark): see also UUOC
    – Anthony Sottile
    Sep 3 at 3:59







1




1




(warning: snark): see also UUOC
– Anthony Sottile
Sep 3 at 3:59




(warning: snark): see also UUOC
– Anthony Sottile
Sep 3 at 3:59


Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke