Home
Back To Top
Home
Input a line of text and display on standard output
# echo Test
string for command exercises
Test string
for command exercises
Print value of a variable
# var1=10
# echo The
value of variable var1 = $var1
The value of
variable x = 10
Note: The ‘-e’ option in Linux acts as interpretation of escaped
characters that are backslashed.
‘\b’– Backspace which removes all the spaces in between.
With backslash interpreter (-e)
# echo -e
"Test string \bfor command \bexercises "
Test
stringfor commandexercises
Without backslash interpreter (-e)
# echo
"Test string \bfor command \bexercises "
Test string
\bfor command \bexercises
‘\n’ – New line to add new line from where it is used.
With backslash interpreter (-e)
# echo -e
"Test string \nfor command \nexercises "
Test string
for command
exercises
Without backslash interpreter (-e)
# echo
"Test string \nfor command \nexercises "
Test string
\nfor command \nexercises
‘\t’ – Horizontal tab to have horizontal tab spaces.
With backslash interpreter (-e)
# echo -e
"Test string \tfor command \texercises "
Test
string for command exercises
Without backslash interpreter (-e)
# echo
"Test string \tfor command \texercises "
Test string
\tfor command \texercises
Using new Line ‘\n‘ and horizontal tab ‘\t‘ simultaneously.
With backslash interpreter (-e)
# echo -e
"Test string \n\tfor command \n\texercises "
Test string
for command
exercises
Without backslash interpreter (-e)
# echo
"Test string \n\tfor command \n\texercises "
Test string
\n\tfor command \n\texercises
With backslash interpreter (-e) Sequence matters
# echo -e
"Test string \t\nfor command \t\nexercises "
Test string
for command
exercises
With backslash interpreter (-e)
# echo "Test string \t\nfor command
\t\nexercises "
Test string
\t\nfor command \t\nexercises
‘\v’ – Vertical tab to have vertical tab spaces.
With backslash interpreter (-e)
# echo -e
"Test string \vfor command \vexercises "
Test string
for command
exercises
Without backslash interpreter (-e)
# echo
"Test string \vfor command \vexercises "
Test string
\vfor command \vexercises
Using new Line ‘\n’ and vertical tab ‘\v’ simultaneously.
With backslash interpreter (-e)
# echo -e
"Test string \n\vfor command \n\vexercises "
Test string
for command
exercises
Without backslash interpreter (-e)
# echo
"Test string \n\vfor command \n\vexercises "
Test string
\n\vfor command \n\vexercises
With backslash interpreter (-e)
# echo -e
"Test string \v\nfor command \v\nexercises "
Test string
for command
exercises
Without backslash interpreter (-e)
# echo
"Test string \v\nfor command \v\nexercises "
Test string
\v\nfor command \v\nexercises
Note: no difference observed in combinational use of new line and
vertical tab option, multiple time usage can get you different results.
‘\r’ – carriage return to have specified carriage return in output.
With backslash interpreter (-e)
# echo -e
"Test string \rfor command exercises "
for command
exercises
Without backslash interpreter (-e)
# echo
"Test string \rfor command exercises "
Test string
\rfor command exercises
‘\c’ – suppress trailing new line to continue without emitting new
line.
Without backslash interpreter (-e)
# echo -e
"Test string \cfor command exercises "
Test string [test
~]#
Without backslash interpreter (-e)
# echo
"Test string \cfor command exercises "
Test string
\cfor command exercises
Omit printing trailing new line using option ‘-n‘.
# echo -n
"Test string for command exercises "
Test string
for command exercises [test ~]#
‘\a’ – alert return to have sound alert.
With backslash interpreter (-e)
# echo -e
"Test string \afor command exercises "
Test string
for command exercises
Note: Make sure to check Volume key, before firing.
Without backslash interpreter (-e)
# echo
"Test string \afor command exercises "
Test string \afor
command exercises
Print all the files/folder using echo command (simulate ls command).
# echo *
Print files of a specific kind.
# echo *.txt
To append a text to a file instead of sending it to standard output
# echo
"Test content" > testfile
# cat testfile
Test content
Prints " (quote, octal ASCII
character 42)
echo "QUOTATION MARK"
echo -e "\042" # Prints " (quote, octal ASCII
character 42).
echo "=============="
Quote
(") framed by tabs.
echo $'\t \042 \t' # Using ASCII Values
echo $'\t \x22 \t' # Using Hexadecimal Values
Assigning
ASCII characters to a variable.
quote=$'\042' # " assigned to a variable.
echo "$quote Quoted string $quote and this
lies outside the quotes."
Concatenating
ASCII chars in a variable.
triple_underline=$'\137\137\137' # 137 is octal ASCII code for '_'.
echo "$triple_underline UNDERLINE
$triple_underline"
Assigning
Octal character values to a variable.
ABC=$'\101\102\103\010' # 101, 102, 103 are octal A, B, C.
echo $ABC
Reference:-
http://www.asciitable.com/
Back To Top
Home
No comments:
Post a Comment