The echo
command in Bash is used to display a line of text or a variable value in the terminal. It is one of the most commonly used commands for outputting information, making it essential for scripting and command-line operations.
The basic syntax of the echo
command is as follows:
echo [options] [arguments]
-n
: Suppresses the trailing newline, allowing the next output to appear on the same line.-e
: Enables interpretation of backslash escapes (e.g., \n
for a new line, \t
for a tab).-E
: Disables interpretation of backslash escapes (this is the default behavior).Here are some practical examples of using the echo
command:
echo "Hello, World!"
echo -n "This is on the same line."
echo " And this continues."
echo -e "First line\nSecond line"
name="Alice"
echo "Hello, $name!"
echo -e "Tab character:\tTabbed text"
echo -n
when you want to print multiple outputs on the same line without line breaks.-e
option.echo
, as unquoted variables can lead to word splitting or globbing issues. Always quote your variables to avoid unexpected behavior.