Echo Command - MAN Page explained with Examples

Echo Command - MAN Page explained with Examples

·

3 min read

echo

  • Write output to standard input
OptionUsage
-nDo not appened to a new line. The terminal curser will be in the same line as the output instead of being in a new line by default.
-eenables interpretation of \ backslash escapes
-EOpposite of -e. Explicitly supress interpretation of backslash escapes
\aAlert through Volume. Make sure your volume is high. It will ring a ting on an output
\bBackspace, removes all spaces between the texts
\bIt removes the n no. of character occurring before the \b used. Depending on the no. of times used
\cSuppress further output. Will not output whatever is written after \c
\eEscape character. Omits the just next single character succeeding to \e
\nCreates a new line
\rCarriage return. Will not return whatever is return before \r. opposite of \c
\tHorizontal tabs. Use tabs as spaces.
\vVertical tab space. In a slanting manner

Detailed options:

  1. -n - Do not appened to a new line. The terminal curser will be in the same line as the output instead of being in a new line by default.
    [aaakriti@aakriti ~]$ echo -n "Harry Potter"
    Harry Potter[aaakriti@aakriti ~]$ write your next command here
    
  2. \a - Alert through Volume. Make sure your volume is high. It will ring a ting on an output.
    [aaakriti@aakriti ~]$ echo -e "\aHarry Potter"
    Harry Potter
    
  3. \b - Backspace, removes all spaces between the texts
    [aaakriti@aakriti ~]$ echo -e "Harry \bPotter"
    HarryPotter
    
  4. \b - It removes the n no. of character occurring before the \b used. Depending on the no. of times used.
    [aaakriti@aakriti ~]$ echo -e "Harry\b\bPotter"
    HarPotter
    
  5. \c - Suppress further output. Will not output whatever is written after \c
    [aaakriti@aakriti ~]$ echo -e "Harry \c Potter is my favorite"
    Harry
    
  6. \e - Escape character. Omits the just next single character succeeding to \e
    [aaakriti@aakriti ~]$ echo -e "\eHarry"
    arry
    
  7. \n - Creates a new line
    [aaakriti@aakriti ~]$ echo -e "Harry \nPotter \nis \nmy \nfavorite"
    Harry
    Potter
    is
    my
    favorite
    
  8. \r - Carriage return. Will return whatever is after \r. opposite of \c
    [aaakriti@aakriti ~]$ echo -e "Harry \r Potter is my favorite"
    Potter is my favorite
    
  9. \t - Horizontal tabs. Use tabs as spaces.

    [aaakriti@aakriti ~]$ echo -e "Harry \tpotter is my favorite"
    Harry   potter is my favorite
    
    [aaakriti@aakriti ~]$ echo -e "Harry \tpotter \tis \tmy \tfavorite"
    Harry   potter  is      my      favorite
    
  10. \v - Vertical tab space. In a slanting manner.
    [aaakriti@aakriti ~]$  echo -e "Harry \v Potter"
    Harry
         Potter
    

Other tricks

OptionUsage
echo *Lists all files and folders
echo $xecho value of a variable
\n + \tnew line + tab
\n + \vnew line + verticle tab
echo "Test" > testpage.logwill add contents to a file
1. echo 'Harry "Potter"'
2. echo "Harry \"Potter\""
Harry "Potter"
echo $(command)Output of the command
echo ~home folder
echo {1..5}1 2 3 4 5
echo $((50*2))100
1. echo -e "\033[1;37mWHITE"
2. echo -e "\033[0;34mBLUE"
Display in respective colors

Fun tricks

  • Make someone get lost in dark black world of linux: echo -e "\033[0;30mBLACK"