echo

Display message on screen.

Syntax
     echo [-n] [string ...]

Key
   -n   Do not print the trailing newline character.	 This may also be
        achieved by appending `\c' to the end of the string, as is done by
        iBCS2 compatible systems.

To produce a default beep:

$ echo '^G^G^G^G'
Enter the ^G characters (which represent ASCII 7, the BEL character) by typing Ctrl-v Ctrl-g

The echo utility exits 0 on success, and >0 if an error occurs.

Examples

$ echo "Hello World"

Echo can also display in color using Escape sequences for foreground (30..37) and background (40..47) colours. Note that Terminal.app preferences will give much finer control over colors so you may prefer to use that for setting the Background and Selected text colors.

$ COL_BLUE="\x1b[34;01m"
$ COL_RESET="\x1b[39;49;00m"
$ echo -e $COL_BLUE"Important Message: "$COL_RESET"This is a message"

Here is a shell script to display all the color combinations:

 #!/bin/bash
 #
 echo ---Bg---40---41---42---43---44---45---46---47
 for i in {30..37} # foreground
 do
 echo -n -e fg$i- 
 for j in {40..47} # background
 do
 echo -n -e '\E['$i';'$j'm SS64'
 tput sgr0 # Reset text attributes to normal without clear
 done
 echo # newline
 done
 
 echo -- Clear BG --
 for n in {30..37} # foreground
 do
 echo -e fg$n '\E['$n';'01'm SS64'
 tput sgr0 # Reset text attributes to normal without clear
 done

QED - Quod erat demonstrandum. [Thus it is proven.]

Related:

echo man page - Apple.com
lpr - Print files
printf - Format and print data
say - Convert text to audible speech



Back to the Top

© Copyright SS64.com 1999-2012
Some rights reserved