echo Command in Linux

In this blog we will learn about echo command .We can use a echo command to declare variables and we can use these variables with our echo command  in Linux . First of all lets open our terminal , We can press ctrl+alt+ t to do this .

1.First of all to use echo command you just use $echo and then some text for example hello world and press Enter and what it does it just displays whatever you right after this echo command so it echoes anything which you right after the keyword echo.

The use of this echo command comes when you are using some scripting for example bash scripting and then it becomes really important sometimes to use echo .

There is a good practice to use echo also which is $echo and then you use double quotes around your text or whatever you want to display so for example hello world and then it displays the same content but it’s better to use double quotes around your text .

2.In order to declare a variable you just need to give a name to your variable for example myvar for myvariable and then give equals to sign so it’s important here to note that don’t provide any space in betweenand then give any value to your variable for example mark and when you press ENTER it does nothing but whenever you want to you know know the value of this variable you can use echothen the dollar symbol so justuse this kind of a dollar symbol and then the name of your variable for example myvar and press ENTER and it will display the content of the variable .
So commands : $variablename="value" , $echo $variablename

 Want to let you know that the variable is only valid for this session of the termin as soon as you will close the terminal then your variable value will be gone so it’s only valid for this session .

3.Now there are some options you can use with echo .When for example you want to escape something then what you can do , just use echo and then use -e flag for escape and use single quotes and write some text inside it and one word with backslash . Command : $echo -e 'text \(what you want to escape)text continue'

Another example : $echo -e 'text1 \n text2' .It will print text1 and text2 in newline .

This is all about echo command in this blog .

Partner Sites

Be the first to comment

Leave a Reply

Your email address will not be published.