
- Unix Commands Reference
- Unix - Tutorial Home
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
echo command in Linux with Examples
Name
echo - display a line of text
Synopsis
echo [SHORT-OPTION]... [STRING]... echo LONG-OPTION
Description
The echo
is a bash builtin command that is used to echo the string(s) to the standard output. command that is used to echo the string(s) to the standard output.
Options
The program accepts the following options.
-n do not output the trailing newline -e enable interpretation of backslash escapes -E disable interpretation of backslash escapes (default) --help display this help and exit --version output version information and exit If -e is in effect, the following sequences are recognized: \\ backslash \a alert (BEL) \b backspace \c produce no further output \e escape \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \0NNN byte with octal value NNN (1 to 3 digits) \xHH byte with hexadecimal value HH (1 to 2 digits)
Examples
echo a list of strings on command line.
$ echo "Shambhavi Vidya" Shambhavi Vidya $ $ echo "Shambhavi \nVidya" Shambhavi \nVidya $
-e
option enables the interpretation of backslash escape sequences inside the strings.
\n
option creats a newline from where it is used.
$ echo -e "Shree \nLaxmi" Shree Laxmi
String Laxmi is printed after the newline.
-n
option suppresses the output trailing new line.
$ echo -n -e "Shree \nLaxmi" Shree Laxmi$
After the last string Laxmi, the newline has been suppressed and command prompt $ appears on the same line immediately after the string Laxmi ends.
Using the option \b
inside the string removes the whitespace between the strings.
$ echo -e "Shree \bLaxmi" ShreeLaxmi
Display output of a command in echo's argument. Use $(command) option of bash shell to show current date.
$ echo "The date is: $(date)" The date is: Wed Mar 24 20:18:00 IST 2021 $ echo "The date is: $(date +%D)" The date is: 03/24/21
Use \n\v simultaneously inside a string to print string on a new line and skip one line.
$ echo -e "\n\vTutorials\n\vPoint\n\vis\n\vhosting\n\velearning\n\vcontet" Tutorials Point is hosting elearning contet $
Use \uXXXX
option inside a string to display unicode character. Unicode value of Hindi character क is 0915, म is 092e and ल is 0932.
$ echo -e 'my name is \u0915\u092e\u0932' my name is कमल $