Pipeline question


Link to what I am working on: https://www.codecademy.com/courses/learn-the-command-line/lessons/redirection/exercises/pipes?action=resume_content_item

Hello. I am a bit confused on pipelines. So a pipeline takes the output and uses it as an input for the thing on the right.

I get that for example $ cat volcanoes.txt | wc takes the output of the left thing which would be all the names and word counts it, basically wc cat volcanoes.txt

I am confused on this part:
$ cat volcanoes.txt | wc | cat > islands.txt
So the names get piped into wc, giving us three numbers, and piping them into cat??? So would that make wc [number] [number] [number]? But that doesn’t make sense. And then takes the wc and replaces it with the information on island.txt?


The output of wc is 3 numbers, which is sent to cat, which doesn’t really do anything, it just repeats, you can remove it without changing the outcome

> writes a program’s output to a file
< writes a file’s content to a program’s input

You could also have written:

wc < volcanoes.txt > islands.txt

Or, since wc can read from files:

wc volcanoes.txt > islands.txt

volcanoes.txt is given to wc as an argument (not stdin). In python you’d find that in sys.argv:

# hello.py
import sys
print('hello', sys.argv[1])
$ python hello.py bob
hello bob