Echo Command in Linux with Examples

Posted in

Echo Command in Linux with Examples
sangeeta.gulia

Sangeeta Gulia
Last updated on November 22, 2024

    Getting various information from a file or in a terminal is a frequent operation in Linux Operating Systems . It can be used to debug and get various system information. In this article, we are going to discuss the echo command which allows us to perform these tasks.

    Echo Command in Linux

    In Linux, the echo command is used to show a line of text/string that has been supplied as an argument. This is a built-in command that outputs status text to the screen or a file. It's typically used in shell scripts and batch files. The syntax for this command is "echo [option] [string]".

    Options with Echo command

    1. \b

    it eliminates all the spaces in between the text

    Example :

    echo -e "hello \bdevelopers"

    2. \c

    To continue without emitting a new line, use the backspace interpreter '-e' to suppress the trailing new line.

    Example :

    echo -e "hello \cdevelopers"

    3. \n

    This option generates a new line from the current one.

    Example :

    echo -e "hello \ndevelopers"

    4. \t

    Horizontal tab spaces are created with this option.

    Example :

    echo -e "hello \tdevelopers"

    5. \r

    To have a given carriage return in output, use the backspace interpreter '-e'.

    Example :

    echo -e "hello \rdevelopers"

    6. \v

    Vertical tab spaces are created with this option.

    Example :

    echo -e "hello \vdevelopers

    7. \a

    To have a sound alert, use the backspace interpreter '-e'.

    Example :

    echo -e "\ahello developers

    8. echo *

    This command, like the ls command, prints all files and directories.

    Example :

    echo *

    9. -n

    This option is used to prevent the echoing of the last new line.

    Example :

    echo -n "hello developers"

    Conclusion

    In this article, we discussed the description of the echo command and its various options. We realize that the echo command provides various options to format the given output. The formatting options can be listing the directories and files, sound alert, generating new lines, tab spaces, etc.

    People are also reading:

    Leave a Comment on this Post

    0 Comments