echo

Display message on screen.

Syntax
     echo [options]... [String]...

Options

 -n
     Do not output the trailing newline.

 -E
     Disable the interpretation of the following backslash-escaped characters.

 -e
     Enable interpretation of the following backslash-escaped
     characters in each String:

    \a          alert (bell)

    \b          backspace

    \c          suppress trailing newline

    \e          escape 

\f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \\ backslash \0NNN the character whose ASCII code is NNN (octal); NNN can be 0 to 3 octal digits.

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.

This is a BASH shell builtin, to display your local syntax from the bash prompt type: help echo
There is also an echo utility (man echo) , but the shell built-in version will generally take precedence.

Examples

echo "Hello World"

DEMO=Testing123
echo "$DEMO"
# Testing123

echo "with quotes we can echo
several lines at a time"

Echo can also display in color using Escape sequences for foreground (30..37) and background (40..47) colours.
Terminal.app preferences give much finer control over colors (background + selected text).

$ 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 macOS commands:

lpr - Print files
printf - Format and print data
say - Convert text to audible speech
wall - Write a message to users


 
Copyright © SS64.com 1999-2019
Some rights reserved