Can't get ASCII art to echo to console

user3698316 picture user3698316 · Aug 9, 2014 · Viewed 25.7k times · Source

I'm new to Bash scripting, and this here is just puzzling to me. I'm adding ASCII art to a project, and can't seem to figure out how to escape certain characters. Would someone please help me get the following code below to work?

Whenever I tried adding slashes as escape characters to fix the errors, the slashes also wound up printing to console on execution. This ruins the image. I don't understand what I'm doing wrong, so I've posted the code below in the hopes that someone will take a moment to show me the right way. Please? I've removed the quotes to prevent more clutter.

echo -en "\E[31m"
echo
echo       _,.
echo     ,` -.)
echo    '( _/'-\\-.              
echo   /,|`--._,-^|          ,    
echo   \_| |`-._/||          ,'|      
echo     |  `-, / |         /  /     
echo     |     || |        /  /      
echo      `r-._||/   __   /  / 
echo  __,-<_     )`-/  `./  /
echo '  \   `---'   \   /  /
echo     |           |./  / 
echo     /           //  /    
echo \_/' \         |/  /        
echo  |    |   _,^-'/  /             
echo  |    , ``  (\/  /_       
echo   \,.->._    \X-=/^        
echo   (  /   `-._//^` 
echo    `Y-.____(__}             
echo     |     {__)          
echo           ()`    

Answer

that other guy picture that other guy · Aug 9, 2014

Quotes in bash are important syntactic elements, not clutter. However, to print ASCII art, save yourself the trouble of proper quoting and escaping and just use a here document:

cat << "EOF"
       _,.
     ,` -.)
    '( _/'-\\-.               
   /,|`--._,-^|            ,     
   \_| |`-._/||          ,'|       
     |  `-, / |         /  /      
     |     || |        /  /       
      `r-._||/   __   /  /  
  __,-<_     )`-/  `./  /
 '  \   `---'   \   /  / 
     |           |./  /  
     /           //  /     
 \_/' \         |/  /         
  |    |   _,^-'/  /              
  |    , ``  (\/  /_        
   \,.->._    \X-=/^         
   (  /   `-._//^`  
    `Y-.____(__}              
     |     {__)           
           ()`     
EOF

Make sure not to remove the quotes here. They are not optional.