Linux provides the echo
command in order to print given text or string into the command line interface. The echo command can be used in different shell environments like Bash, Csh, etc. We can use the echo command in the bash interactive shell or in a bash script. The usage of the echo command in a bash script is very same as the bash interactive shell. In this tutorial, we examine how to use the echo command in the bash script.
echo Command Syntax
The echo command has the following syntax.
echo OPTION STRING
- OPTION is the echo command option that can be used to alert, tab, etc. for the provided STRING.
- STRING is printed to the terminal or standard output.
Print Text In Bash Script
The most popular usage for the echo command is printing given text or string into the terminal or standard output. In the following example, we print “I like linuxtect” into the terminal.
#!/bin/bash
echo "I like linuxtect"
Print Text with Tabs In Bash Script
The echo command can be used to print different formats like tabs etc. We can use the \t
inside string and provide -e
to the echo command.
#!/bin/bash
echo -e "I\tlike\tlinuxtect"
Print The Bash Script Name with echo Command
The echo command can be used to print the bash file name into the terminal. The $0
is used to store the current bash script file name.
#!/bin/bash
echo $0
Print Parameters Provided to Bash Script with echo Command
We can also use the echo
command in order to print all parameters to the script file. The $@
is used to print all provided parameters to the bash script file.
#!/bin/bash
echo $@