shelllings

a practical way to learn shell
Log | Files | Refs | README | LICENSE

10_piping.sh (948B)


      1 #!/bin/sh
      2 
      3 # We used this as an example for data direction and up until this point
      4 # we had to run separate commands.
      5 #
      6 # $ head -n 50 LICENSE > 09_file
      7 # $ wc -w 09_file
      8 #
      9 # But now we can combine this using pipes. The '|' symbol is used to 
     10 # basically accomplish what was shown before
     11 #
     12 # $ head -n 50 LICENSE | wc -w
     13 #
     14 # Notice that we did not have to add a file onto wc -l or even enter
     15 # a standard input environment.
     16 #
     17 # As for the actual exercise, change all of these commands into pipes.
     18 # NOTE the testing of this case is very sensitive, try being concise
     19 # and leave unnecessary whitespace out of your answers. Leave the white
     20 # space needed for human readability.
     21 
     22 cat LICENSE > file
     23 wc -w file
     24 
     25 ls -A "$HOME" > file
     26 wc -l file
     27 
     28 # As a fun exercise, run that command above and see how cluttered your
     29 # home directory is. In fact, in many modern shells, "$HOME" isn't
     30 # needed, '~' is enough. 'ls -A ~' will list out your home directory