echo command in Linux/Unix
echo command in Linux/UNIX is primarily used to :
1. To display message ( it is used in shell scripts).
2. To evaluate shell variables (like echo $PATH)
Examples
1. echo "my name is xyz" -- double quotes is not mandatory
output :
2. echo $SHELL
output:
echo can also be combined with different commands like
1. echo " today date is `date`"
output:
echo used different escape sequence which are listed below :
* note that all escape sequence in Linux is use with "-e" option other wise it is not recognized by Linux
1. /b - use for backspace
a. echo " my name is\b xyz" --- used without -e option
output :
b. echo -e " my name is\b xyz" --used with -e option
output :
2. /c - No new line (cursor appear in same line)
echo -e " my name is xyz \c"
output:
3. \n - Newline(same as enter)
echo command in Linux/UNIX is primarily used to :
1. To display message ( it is used in shell scripts).
2. To evaluate shell variables (like echo $PATH)
Examples
1. echo "my name is xyz" -- double quotes is not mandatory
output :
$ echo "my name is xyz"
my name is xyz
$ echo my name is sandeep
my name is sandeep
$
my name is xyz
$ echo my name is sandeep
my name is sandeep
$
2. echo $SHELL
output:
$echo $SHELL
/bin/bash
--this output can be different depending upon the shell you are using./bin/bash
echo can also be combined with different commands like
1. echo " today date is `date`"
output:
$ echo "today date is `date`"
today date is Sun Jan 8 13:16:04 IST 2012
$
today date is Sun Jan 8 13:16:04 IST 2012
$
* note that all escape sequence in Linux is use with "-e" option other wise it is not recognized by Linux
1. /b - use for backspace
a. echo " my name is\b xyz" --- used without -e option
output :
$echo "my name is/b xyz"
my name is/b xyz
my name is/b xyz
b. echo -e " my name is\b xyz" --used with -e option
output :
$ echo -e "my name is\b xyx"
my name i xyx
my name i xyx
echo -e " my name is xyz \c"
output:
$ echo -e "my name is xyz\c"
my name is xyz$
* note that prompt appear in same line along with the output.my name is xyz$
3. \n - Newline(same as enter)
echo -e " my name is xyz \n"
Output:
4 . \t - Tab
echo -e " my\tname\tis\txyz"
output:
5 . \f - formfeed
Output:
$ echo -e "my name is xyz\n"
my name is xyz
$
my name is xyz
echo -e " my\tname\tis\txyz"
output:
$ echo -e "my\tname\tis\txyz"
my name is xyz
$
my name is xyz
$
echo -e " my\fname\fis\fxyz"
output :
other options are :
\a - bell
\r - carriage return
\\ - backslash
output :
$ echo -e "my name\fis\fxyz "
my name
is
xyz
$
my name
is
xyz
$
\a - bell
\r - carriage return
\\ - backslash
If You Liked This Post Please Take a Time To Share This Post
0 comments:
Post a Comment