What is echo command?
The echo command in Linux is used to display text string that is passed to it as an argument. This is a built in command that is mostly used in automation shell scripts to output debug statements or status of some execution, progress to the screen.
Syntax :
echo [option] [string]Syntax :
echo [string]For Example: Below command, outputs the string passed to echo command to terminal.
$ echo "Linux Commands"
Linux CommandsIf you want to write this same string to some file, then we can use redirects to write the output of echo command to file as,
$ echo "Linux Commands" > helloworld.txtOptions of echo command
NOTE :- -e here enables the interpretation of backslash escapes.
1. \b : It removes all the spaces in between the text.
For Example:
$ echo -e "echo \bcommand \bLinux"
echocommandLinux2. \c : Suppress trailing new line with backspace interpretor ‘-e‘ to continue without emitting new line.
For Example:
$ echo -e "echo \ccommand Linux"
echoIn above example, text after \c is not printed and omitted trailing new line.
3. \n : This option creates new line from where it is used.
For Example:
$ echo -e "Welcome to \nLinux \noperating system"
Welcome to
Linux
operating systemIn the above example,text after \n is printed on next line.
4. \t : This option is used to create horizontal tab spaces.
For Example:
$ echo -e "Welcome \tto \tLinux \toperating \tsystem"
Welcome to Linux operating system5. \r : Carriage return with backspace interpretor ‘-e‘ to have specified carriage return in output.
For Example:
$ echo -e "Welcome to Linux \roperating system"
operating system In the above example, text before \r is not printed.
6. \v : This option is used to create vertical tab spaces.
For Example:
$ echo -e "Welcome to \vLinux \voperating \vsystem"
Welcome to
Linux
operating
system7. \a : alert return with backspace interpretor ‘-e‘ to have sound alert.
For Example:
$ echo -e "\aWelcome to Linux operating system"
Welcome to Linux operating systemThis command when executed, it will produce an alert sound or Bel .
8. echo * : This command will print all files/folders, similar to “ls” command .
For Example:
$ echo *
Desktop Documents Downloads linux-color-coding Music Pictures Public Templates textfile.txt Videos$ ls
Desktop Downloads Music Public textfile.txt
Documents linux-color-coding Pictures Templates Videos9. -n : This option is used to omit echoing trailing newline .
For Example:
$ echo -n "Linux color coding"
Linux color coding