What escape character will add a vertical tab to the screen if issued within a script?

echo is a shell built-in command that is used to print the information/message to your terminal. It is the most popular command that is available in most Linux distributions and is typically used in bash scripts and batch files to print status text/string to the screen or a file.

In this article, I will show you how to use the echo command in Linux shell scripts.

How to Work With echo Command in Linux

When learning shell scripting this is the first command you will learn about to print something in your terminal. echo will print the output to stdout or you can also redirect the output to files. There are two versions of echo. One is bash builtin and the second one is an external command.

NOTE: Always builtin version takes precedence over external command.

Use the type command to get the path information about the echo command.

$ type -a echo

echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo

To get the list of options supported for the echo command, use the help option.

$ help echo

Example 1: No Arguments to echo Command

When you call the echo command without passing any arguments it prints an empty line.

$ echo
What escape character will add a vertical tab to the screen if issued within a script?
an echo with no arguments

Example 2: Use echo With and Without Quotes

You can pass arguments to echo command with or without quotes. Take a look at the below example. I am printing the same statement with single and double quotes and without quotes and getting the same result.

$ echo Love Linux And OpenSource
$ echo "Love Linux And OpenSource"
$ echo 'Love Linux And OpenSource'
What escape character will add a vertical tab to the screen if issued within a script?
echo print output

There is a significant difference in when to use single and double quotes. When you use single quotes and any word contains a single quote then it will be treated as the end of quotes. Take a look at the below example where isn’t contains single quotes and is treated as the end of quotes.

$ echo 'Windows isn't opensource'
> ^C

In this case, using double quotes will make more sense.

$ echo "Windows isn't opensource"
Windows isn't opensource
What escape character will add a vertical tab to the screen if issued within a script?
Echo Single Vs Double Quotes

Example 3: Printing Variables with Echo Command

Values stored in variables can be printed to the terminal using the echo command. When you use single quotes variable ${VAR} will be interpreted as text and will not be expanded to its assigned value (welcome).

$ VAR="Welcome"
$ echo ${VAR} to shell tips
$ echo "${VAR} to shell tips"
$ echo '${VAR} to shell tips'
What escape character will add a vertical tab to the screen if issued within a script?
Echo Printing Variable Value

Example 4: Redirecting Output to File

You can redirect output to a file instead of printing it in a terminal using the redirection operator ( > and >>).

$ echo " Writing to file redirect.txt " > redirect.txt
$ echo " Appending to file redirect.txt " >> redirect.txt
  • Using > operator will create a new file if not exists and write the data and if the file exists it will overwrite the data.
  • Using >> operator will create a new file if not exists and append the data if the file exists.
What escape character will add a vertical tab to the screen if issued within a script?
Redirecting Output to File

Example 5: Supported Arguments

echo command supports three arguments.

What escape character will add a vertical tab to the screen if issued within a script?
Echo Arguments

By default when you run the echo command new line character is automatically appended at the end. If you want to suppress this behavior use -n flag.

$ echo -n "Love Linux And OpenSource"
What escape character will add a vertical tab to the screen if issued within a script?
Suppress New Line Character

By using the -E flag, the echo statement will treat all backslash-escaped characters as plain text. It is not mandatory to use -E flag because echo by default will not treat these as special characters.

$ echo "\nLove Linux And OpenSource"
$ echo -E "\nLove Linux And OpenSource"
What escape character will add a vertical tab to the screen if issued within a script?
Escaped Characters

To use backslash-escaped characters you have to use -e flag.

Example 6: Escaped Characters

echo command supports escape characters like newline, tab, vertical tab, and a few more. You can get the list of supported characters from the help command.

$ help echo
What escape character will add a vertical tab to the screen if issued within a script?
Escaped Characters

Let’s see frequently used escape characters in action. Note you have to use -e argument for any escape characters to be effective.

Newline character(\n) – This will be one of the commonly used escape characters. When you use \n it will add new lines.

$ echo -e "\nWelcome to \nLinuxShellTips"

Welcome to 
LinuxShellTips

Horizontal tab(\t) – To create horizontal tabs use \t which adds a single tab in your statement.

$ echo -e "\tWelcome to \tLinuxShellTips"
	Welcome to 	LinuxShellTips

Vertical tab(\v) – To create vertical tabs use \v.

$ echo -e "\vWelcome \vto \vLinuxShellTips"

Welcome 
        to 
           LinuxShellTips

Carriage Return(\r) – Removes everything that comes before \r and prints only what is after \r.

$ echo -e "Welcome to \r LinuxShellTips" 
 LinuxShellTips

Suppress Further Output(\c) – Carriage return removes everything that comes before it and \c will remove everything that comes after it.

$ echo -e "Welcome to \c LinuxShellTips"
Welcome to 

If you want to treat any escape characters as normal characters you can use \\. Let’s say you want \c to be treated as a normal value then use \\ followed by escape character \c.

echo -e "Welcome to \\\c LinuxShellTips"
Welcome to \c LinuxShellTips

That’s it for this article. The echo is a simple command to use and very easy to learn. We will catch you up with more shell script-related articles soon.

Which command can be issued to view all users currently logged on to a server and their tasks?

w command is used to show logged-in user names and what they are doing. The information will be read from /var/run/utmp file. The output of the w command contains the following columns: Name of the user.

Which command will display the current working directory onscreen?

To display the location of your current working directory, enter the command pwd.

Which keystroke combination should be used to access the tty3 terminal?

Ctrl+Alt+F3 will bring up the login prompt of tty3.

What directory on a Linux system is commonly used to store log files and spools?

CIT222 Chapter 4- Linux Filesystem Management Key Terms.