In Linux how to use echo command?

Published on Aug. 22, 2023, 12:15 p.m.

In Linux, the echo command is used to output text to the standard output device, which is usually the console screen by default.

Here are some example usages and options for controlling output format and behavior:

  1. Output text:
echo "Hello, world!"
  1. Output a variable:
name="John"
echo "Hello, $name"
  1. Write text to a file:
echo "Some text" > file.txt
  1. Output special characters:
echo "A new line\nAnother line\tTab character"
  1. Disable trailing newline:
echo -n "Some text"
  1. Output environment variables:
echo "$HOME"

These are just some common usage examples, the echo command has other options and parameters that can be used. To get more information, refer to the man pages or use the echo --help command to view available options.

Tags: