Pipes and text
Linux commands: echo
Learn how the Linux echo command prints its argument to the terminal, interpolates variables like $PATH, expands globs and ranges, and appends to a file.
The echo command does one simple job: it prints the argument you pass to it.
This example:
echo "hello"
prints hello to the terminal.
You will use echo all the time, both interactively and inside scripts. It’s the fastest way to see what the shell thinks a value is.
You can append the output to a file with >>:
echo "hello" >> output.txt
Run it twice and output.txt has two hello lines. With a single > the file gets overwritten instead. Be careful with that one.
You can interpolate environment variables. The shell replaces $PATH with its value before echo even runs:
echo "The path variable is $PATH"

Special characters need to be escaped with a backslash \. Take $: echo The cost is $5 prints The cost is because the shell tries to expand a variable named 5, which is empty. Escape it with \$5 and you get the text you wanted:

This is just the start. Since the shell processes the arguments first, echo lets us play with every shell feature.
We can print the files in the current folder:
echo *
We can print only the files that start with the letter o:
echo o*
Any valid Bash (or any shell you are using) feature works here. I use echo *.md a lot to check which files a glob matches before I pass it to rm or mv.
You can print your home folder path:
echo ~

You can also execute a command and print its result to the standard output (or to a file, as you saw):
echo $(ls -al)

Notice that whitespace is not preserved by default. The whole listing gets squashed on one line. Wrap the command in double quotes to keep the newlines:

You can generate a list of strings, for example a range of numbers:
echo {1..5}

This is called brace expansion. It’s handy to create many files at once, like touch chapter{1..5}.md.
The
echocommand works on Linux, macOS, WSL, and anywhere you have a UNIX environment
Lesson completed