echo
echo is used to print the text/string which are entered following the 'echo'
echo Sea is blue. press ENTER
Output:
Sea is blue.
echo with curly brackets{}
echo {a..d} press ENTER
Output:
a b c d
echo {1..5} press ENTER
Output:
1 2 3 4 5
echo {a..d}z press ENTER
Output
az bz cz dz
echo a{a..d}1 press ENTER
Output:
aa1 ab1 ac1 ad1
echo with curly brackets{}
echo {a..d} press ENTER
Output:
a b c d
echo {1..5} press ENTER
Output:
1 2 3 4 5
echo {a..d}z press ENTER
Output
az bz cz dz
echo a{a..d}1 press ENTER
Output:
aa1 ab1 ac1 ad1
echo $variable
let's save a value in a variable
x = 10 press ENTER
echo x is having
the value $x press ENTER
Output:
x is having the value 10
height=10ft press ENTER
echo The bridge is $height tall. press ENTER
Output
The bridge is 10ft tall.
\n (new line)
Use echo and
"\n" together with "-e"
to break the string/texts to new
line.
echo -e "Sea is blue. \nSun is our star \nand
Earth is our home."
---Press ENTER
Output:
Sea is blue.
Sun is our star
and Earth is our home.
If you need more space between the lines , then add more "\n" like "\n \n " , "\n \n \n "
echo -e "Sea is blue. \n\nSun is our star \n\n
\nand Earth is our
home." ---Press ENTER
Output:
Sea is blue.
Sun is our star
and Earth is our home.
\t (tab)
Use echo and
"\t" together with "-e" to add tab space in string.
echo -e "Sea is blue. \tSun is our star \tand
Earth is o\tur home." ---Press ENTER
Output:
Sea is blue. Sun is our
star and Earth is o ur
home.
If you need more space add more \t like
\t\t , \t\t\t
echo -e "Sea is blue. \t\tSun is our star \t\t\tand
Earth is o\t\tur home." ---Press ENTER
Output:
Sea is blue. Sun is
our star and
Earth is o ur
home.
\b (back space)
Use echo and
"\b" together with "-e" to remove spaces between the text where ever required.
echo -e "Sea is blue. \bSun is \bour star \band Earth is our
home." ---Press ENTER
Output:
Sea is blue.Sun isour starand Earth
is our home.
\r ( removes text before " \r " )
echo -e "Sea is blue. \rSun is our star and Earth
is our home."
Output:
Sun is our star and Earth is our home.
echo * (echo SPACE *)---This is
similar to "ls"
echo * --- This will list all the files and folders in present directory.
echo * --- This will list all the files and folders in present directory.
echo *.extension --- to list all the file with the given extension.
echo *.txt --- This will list
all the .txt files present in the current directory.
">" use this
operator with echo to redirect the output to a file.
echo string/text>fileName
echo Sun is our star.>file1 --- The string/text "Sun is our star." is saved in the
file and we can not see this text as standard output , ie, to see this text you
need to open the file1.
> if file1 does not exist already, it creates new file file1 with
the redirected text in the file.
>if file1 already exists , the redirected text will replace the original
content of the file.
">>" use this
operator with echo to redirect the output to a file , appending that file.
echo string/text>>fileName
echo Moon is a satellite.>>file1 --- The string/text " Moon is a satellite." is saved in
the file and we can not see this text as standard output , ie, to see this text
you need to open the file1.
> if file1 does not exist already, it creates new file file1 with
the redirected text in the file.
>if file1 already exists , the redirected text will be appended to
the file file1.
No comments:
Post a Comment