Difference between revisions of "Echo Command"

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search
Line 3: Line 3:
 
OR
 
OR
 
<source lang="bash">printf "%s\n" $varName</source>
 
<source lang="bash">printf "%s\n" $varName</source>
 +
 +
==Generating Output With echo command=
 +
Use echo command to display a line of text or variable value. It offer no formatting option. It is good command to display simple output.
 +
===echo Command Examples===
 +
<source lang="bash">#!/bin/bash
 +
# Display welcome message, computer name and date
 +
echo " *** Demo Shell Script *** "
 +
echo " Host : $(hostname) @ $(date)"
 +
echo "-------------------------------------"
 +
 +
# Define variables
 +
BACKUP="/nas05"
 +
NOW=$(date +"%d-%m-%Y")
 +
 +
# Let us start backup
 +
echo "Dumping MySQL Database to $BACKUP/$NOW"
 +
</source>

Revision as of 18:56, 30 August 2009

To display the value of a variable either use echo or printf command as follows:

echo $varName

OR

printf "%s\n" $varName

=Generating Output With echo command

Use echo command to display a line of text or variable value. It offer no formatting option. It is good command to display simple output.

echo Command Examples

#!/bin/bash
# Display welcome message, computer name and date
echo " *** Demo Shell Script *** "
echo " Host : $(hostname) @ $(date)"
echo "-------------------------------------"

# Define variables
BACKUP="/nas05"
NOW=$(date +"%d-%m-%Y")

# Let us start backup
echo "Dumping MySQL Database to $BACKUP/$NOW"