Linux command echo with flags and examples
![]() |
| echo command |
Simple echo command
![]() |
| simple echo command |
$echo Your text
For example hello world and press ENTER. And what it does according to its name it just displayed whatever you write after this "echo command".
Now you may say that it's good for nothing because it's just echoing whatever we write after this and it's not really useful.
For example bash scripting and then it becomes really important sometimes to use "echo" and maybe in the next session, I will show you a brief introduction to scripting also and then you will be able to understand how echo is important.
create a variable using echo
![]() |
| create a variable |
$variableName=value
How to use variables in terminal or in Linux. In order to declare a variable you just need to give a name to your variable.
For example "myvariable" and then give equals to sign (=) So it's important here to note that I'm not providing any space between the variable name and equal to symbol.
For example, I will give "mark" and when you press ENTER. It does nothing but whenever you want to know the value of this variable.
$echo $variableName
You can use "echo" and then the dollar symbol ($) and then the name of your variable.
For example "myvariable" and press ENTER and it will display the content of this variable.
This variable is only valid for this session of the terminal. As soon as you will close the terminal then your variable value will be gone.
Escape sequence in echo
![]() |
| escape sequences |
$echo -e 'yourContent with escape sequence'
For example, I will just use echo and then I will use the "-e" flag for escape and then I will use single quotes (').
Whenever you will give this flag called "-e" it will enable interpretation of backslash as an escape sequence.
Some escape sequence is,
- "\n" - Newline
- "\t" - Horizontal Tab
- "\v" - Vertical Tab
- "\b" - Backspace
Conclusion
For more sequences, You can search for using "Man command" and you will be good to go.
HAVE A NICE DAY💖



