echo
echo
: print a string of text.
The echo
command is a built-in command in various operating systems (Unix, Linux, macOS, and Windows), used to display a line of text or a string that is passed as an argument. It's commonly used in shell scripts and batch files to output status messages to the screen or a file.
While echo
isn't a Git-specific command, it's frequently used in shell scripts and command-line interactions related to Git workflows to display information, construct commands, or manipulate files.
The name "echo" may seem like an odd choice for a command that outputs text. It doesn't have anything to do with sound or acoustics. The name comes from early computing history, where "echo" was used to describe a machine sending back a copy of what was sent to it (just like an echo in real life). In this context, the echo
command sends back (to the screen or a file) the text that you give it.
Redirecting output
The echo
command is commonly used to put a piece of text into a file. You can redirect the output of echo
to a file using the >
or >>
operators. The >
operator overwrites the file if it already exists, while >>
appends the output to the end of the file, preserving any existing content. Here's an easy way to remember the difference:
>
: 1 arrow = keep 1 thing = keep mine>>
: 2 arrows = keep 2 things = keep yours and mine
Examples
Display a simple message:
echo "Hello, World!"
Hello, World!
Write the output to a new file, overwriting it if it exists:
echo "Hello, World!" > file.txt
Hello, World!
Append the output to an existing file:
echo "This is appended text." >> file.txt
Hello, World!
This is appended text.