echo PDF Print E-mail

echo
You can use the echo command in different ways.  Basically echo displays a text string to standard output.

 

Enter "echo", followed by a line of text, and the text will be displayed on the next line.

echo “Hello I am writing a Bash Shell script”
Hello I am writing a Bash Shell script

There are several formatting options for echo.  If you use it with the -n switch, you can prevent it from creating a new line at the end of the text output.

Use it with the -e switch, and you'll be able to use some "backslash" options.  For example, to insert a vertical tab into a line of text, use the -e switch with the \v option.

To insert a horizontal tab, use the \t option

To split the output on to two lines, use the new-line sequence, \n.

And, if you want to insert a backslash into the text, just use two consecutive backslashes.

You're not limited to just echoing text messages.  You can also use a wildcard character to show a list of files that you have in the current directory.

echo *
files installer.sh

Then, combine the file listing with a text message:

echo -e "These are my files:\n" *
These are my files:
files installer.sh


If you have a very long command to enter, you may find it handier to break it up into two or more lines.  You can do that by entering part of the command, followed by a \.  On the next line, you'll then see a different command prompt, waiting for you to enter the rest of the command.   So, if you want to echo a text string, you can do that by breaking the command into two separate lines.   First, you'll enter:

echo -e \
>

To complete the command, enter the text string that you want to echo on the next line.

echo -e \
> "Hello I am writing a \v Bash Shell script."

Hello I am writing a
Bash Shell script.

basic.sh

#!/bin/sh
# echo
echo This is text with no quotes
echo "This is text without extra spaces but with quotes"
echo "This is text        with spaces and quotes"
echo -e "This is text\v on a split line"
echo -e "This is text\t with a horizontal tab inserted"
echo -e "This is text\n with a new line"
echo -n "This is text without a new line"


This is text with no quotes
This is text without extra spaces but with quotes
This is text        with spaces and quotes
This is text
on a split line
This is text     with a horizontal tab inserted
This is text
with a new line
This is text without a new linez4@m67:~/scripts$

 

 


Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874