echo's Examples

This command is used to display a text or a string to the standard output or a file. $ echo “This is an article on basic linux commands”

$ echo –e “This is an article is for beginners. \nIt is on basic linux commands

echo prints the arguments to the screen

$ echo hello world

displays the value of variable using echo command

echo the value of variable var is $ 100

we can suppress the last line using the -n option

echo hello world hello world
echo -n hello world

we can add new line to the existing file using echo command

echo hai everyone>>colors,txt

shows all the files in a directory

echo *

prints only the .txt files

echo *txt

we can delete the contents of the file1 without deleting the file1

echo > file1

by giving \n option we can print each word in differnet line

echo -e 'hello \n world \nhai \neveryone

it gives the horizontal tab between two words

echo 'hello \t world'

it gives the vertical space

echo -e 'hai \v everyone \v hai \v friends'

Output:
Hello, World!

echo "Hello, World!"

Output:
Welcome to DevOps School

NAME="DevOps"
echo "Welcome to $NAME School"

Output:
Welcome to DevOps School

NAME="DevOps"
echo "Welcome to $NAME School"

Hello, Welcome to DevOpsSchool!

echo -e "Hello,\nWelcome to DevOpsSchool!"

Name: John Doe

echo -e "Name:\tJohn Doe"

Check the file content using: cat testfile.txt

echo "This is a test file" > testfile.txt

Check the updated file:

cat testfile.txt

echo "This is an appended line" >> testfile.txt

Output:
This will not add a newline

echo -n "This will not add a newline"

Current User: devops
Home Directory: /home/devops
Current Shell: /bin/bash
 

echo "Current User: $USER"
echo "Home Directory: $HOME"
echo "Current Shell: $SHELL"

Today is Wed Jan 29 14:00:00 IST 2025

echo "Today is $(date)"

Prints a line of text or variables to standard output.

echo "Hello, Linux!"

Outputs the text to the terminal or file.

echo "Hello, World!"

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us