Echo Commands Examples:
echo command is used to print the line of text in a different ways, echo command is mostly used when writing an script, to print statement.
AUTHOR of echo is written by Brian Fox and Chet Ramey
1. Printing single line of echo statement
Just we can print an single line of statement
2. Printing exact statement ignore commands within the echo
Printing a echo with exact format lets see the example
if you observer an above example actually $0 and $? are the environment variable values but if you use ‘ ‘ statement within the single quotes it will print as exact
3. Printing an variable value
Lets set an variable value and print the same within the echo statement
In this example defining the variable value as HOMEDIR=/home/ravi/
lets see the other example here
4. Printing \ (back slash) in echo statement
if you run an echo statement with \ (back slash) it will not print in the echo statement because we call \ as escape character
Lets see the examples
5. Enabling interpretation of backslash escapes ‘-e’ option
In front of echo statement if we use ‘-e’ option then we can print echo statement in different formats
Printing same statement in multiple lines. To print echo statement in multiple lines we have to use ‘\n’ along with ‘-e’ option.
6. Get the alert (bell) when it prints statement
Enable your speaker sound and run this, you will hear bell alert. We have to use ‘\a’ option along with ‘-e’ option
7. Run backspace using ‘\b’ option
backspace key lets see the example
as shown in below example echo statement is printed without space
8. No Further output after ‘\c’ option along with ‘-e’ option
if you see an above example after ‘\c’ option there is no output is printed
9. escape character using ‘\e’ option along with ‘-e’
as shown in above example where we use option \e in front of option \e character has been deleted
10. Form feed and print in new line
whenever we use \f option it will clear the screen and print in multiple lines
11. Print in reverse format using echo command
above example we call it as carriage reverse
12. Horizontal tab in between echo statement
Using option ‘\t’ along with ‘-e’ will print the statement with tab space
13. Vertical tab format
where we add ‘\v’ option along with ‘-e’ in echo statement will add vertical tab
14. Disabling interpretation of backslash escapes
As of now we used option ‘-e’ to enabling interpretation in order to disable the interpretation we have to use -E, Do remember difference between option -e and -E. If you want to print the echo statement with horizontal tab and vertical tab format do not use -E option.
15. Print an Hexadecimal value using echo command
As you see above example ‘\x66’ holds the ‘f’ hexadecimal character likewise we can print all the characters.
16. Know echo command version
if you run # echo –version then it will not print its version details because it assume that it is a echo statement and it will print “–verison”.
17. Create an file using echo command
using ‘>’ standard output redirection along with echo statement it will create an file
Along with ‘-e’ option we can use below options
\\ | 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) |
No comments:
Post a Comment