2009-04-10

bash - how to print or display a new line or tab other then using echo

Printing variables or text within bash script is good for debugging. It can trace which line or variables is having problem. echo is the commonly is used for such debugging purpose. But some times we need it to print tabs, new line & other escape strings in a one liner bash. One way to do it is using printf :

e.g.
- display a new line
printf  "this is the first line.\nand this is the second line.\n"


- display a back slash
printf  "a slash is a \\.\n"


- display a horizontal line (like a tab)
printf "display a horizontal line after this.\n \t"

Ciao !!!

No comments: