How To Use Echo Command.
The echo command is one of the most basic and frequently used commands in Linux. The arguments passed to echo are printed to the standard output.
echo is commonly used in shell scripts to display a message or output the results of other commands.
echo Command
echo is a shell builtin in Bash and most of the other popular shells like Zsh and Ksh. Its behavior is slightly different from shell to shell.
There is also a standalone /usr/bin/echo utility, but usually, the shell built-in version will take precedence. We will cover the Bash builtin version of echo.
The syntax for the echo command is as follows:
echo [-neE] [ARGUMENTS]
When the -n option is used, the trailing newline is suppressed.
If the -e option is given, the following backslash-escaped characters will be interpreted:
\\ – Displays a backslash character.
\a – Alert (BEL)
\b – Displays a backspace character.
\c – Suppress any further output
\e – Displays an escape character.
\f – Displays a form feed character.
\n – Displays a new line.
\r – Displays a carriage return.
\t – Displays a horizontal tab.
\v – Displays a vertical tab.
The -E option disables the interpretation of the escape characters. This is the default.
There are a few points to consider when using the echo command.
The shell will substitute all variables, wildcard matching, and special characters before passing the arguments to the echo command.
Although not necessary, it is a good programming practice to enclose the arguments passed to echo in double or single quotes.
When using single quotes ” the literal value of each character enclosed within the quotes will be preserved. Variables and commands will not be expanded.
echo Examples
The following examples show how to use the echo command:
Display a line of text on standard output.
echo Hello, World!
Hello, World!
Display a line of text containing a double quote.
To print a double quote, enclose it within single quotes or escape it with the backslash character.
echo 'Hello "nexonhost"'
echo "Hello \"nexonhost\""
Hello "nexonhost"
Display a line of text containing a single quote.
To print a single quote, enclose it within double quotes or use the ANSI-C Quoting .
echo "I'm a Linux user."
echo
