The echo command is one of the most commonly used commands in Linux and Bash scripting. It is used to print text, variables, command output, and messages in the terminal. If you are learning Bash scripting, the echo command is one of the first commands you should understand.
In Bash scripts, echo is often used to display information, show progress messages, print variable values, create simple output, and write text into files. It is useful for beginners, Linux users, system administrators, and cybersecurity learners who want to create simple and readable scripts.
The echo command displays text or values on the terminal screen.
Basic syntax:
echo "Your message here"
Example:
echo "Welcome to Bash scripting"
Output:
Welcome to Bash scripting
This command simply prints the given message.
Create a Bash script:
nano echo-example.sh
Add the following code:
#!/bin/bashecho "Hello Linux user"echo "This is a Bash script"echo "Learning Bash scripting is useful"
Save and run the script:
chmod +x echo-example.sh./echo-example.sh
Output:
Hello Linux userThis is a Bash scriptLearning Bash scripting is useful
The echo command is commonly used to print variable values.
#!/bin/bashname="Kali Linux"topic="Bash Scripting"echo "Name: $name"echo "Topic: $topic"
Output:
Name: Kali LinuxTopic: Bash Scripting
This is useful when displaying usernames, file paths, system details, or script results.
You can use command substitution with echo.
#!/bin/bashecho "Current user: $(whoami)"echo "Current directory: $(pwd)"echo "Today date: $(date)"echo "Kernel version: $(uname -r)"
This script prints useful system information using Linux commands.
Use the -e option to enable escape characters.
echo -e "Line 1\nLine 2\nLine 3"
Output:
Line 1Line 2Line 3
Use \t to add tab spacing:
echo -e "Name:\tKali Linux"
You can save text into a file using redirection.
echo "This is a log message" > log.txt
To append text without deleting old content:
echo "Another log message" >> log.txt
This is useful for logs, reports, and automation scripts.
#!/bin/bashecho "Security Report" > security-report.txtecho "User: $(whoami)" >> security-report.txtecho "Hostname: $(hostname)" >> security-report.txtecho "Date: $(date)" >> security-report.txtecho "Open network connections:" >> security-report.txtss -tuln >> security-report.txt
This script creates a simple report with system and network information.
The echo command in Linux is simple but very useful in Bash scripting. It helps print messages, show variable values, display command output, and write text to files.
For beginners, learning echo is an important step because almost every Bash script uses it in some way. It is useful for Linux automation, debugging, reporting, logging, and cybersecurity scripting.
Introduction Bash scripting is a powerful way to automate Linux tasks, but writing a script…
Introduction A self-signed SSL certificate is a certificate that is created and signed by the…
Introduction Debugging is an important part of Bash scripting. When a script does not work…
Introduction Cron jobs are used in Linux to run commands or Bash scripts automatically at…
Introduction Pipes are an important feature in Linux and Bash scripting. A pipe allows you…
Introduction The grep, awk, and sed commands are powerful text-processing tools in Linux. They are…