Echo Command in Linux/Unix with ExamplesIn Linux, the echo command can be used for displaying a line of string/text that is passed as the arguments. This command is a built-in that is mostly and widely used in various batch files and shell scripts to outcome status test to a file and screen. Linux distributions permit us to control and set up the system ourselves. In this context, the echo command is one of the most used commands. It's used in batch files and bash scripts to result in a status text on our screen or in a file. The command repeats what we have been told to repeat. This function is very simple but needs to do only that. For instance, we wouldn't get a visible result from shell scripts without echo. Shell is a user interface in which we can input distinct commands like the cat command, head command, tail command, or else the echo Command. The common echo operation is equivalent to every programming language. We make the input (which is in the string form), and it is received and results in again unchanged. Important: The command line interpreter or user interface is also known as the bash shell. It is the standard shell in the distributions of Linux and the text window where we can input our commands. The echo command is an elementary segment of Ubuntu and comes pre-installed on all systems. Syntax of the echo command Implementations of the echo commandThe echo command exists in SymbOS, KolibriOS, HP MPE/iX, ReactOS, Microsoft Windows, IBM OS/2, Digital Research FlexOS, Acorn Computers Panos, Microwave OS-9, Zilog Z80-RIO, MetaComCo TRIPOS, TSC FLEX, Multics, Unix-like and Unix operating systems. Several shells including every Csh-like (like zsh or Bash), Bourne-like shells, and COMMAND.COM as well and cmd.exe execute the echo command as the built-in command. The command also exists inside the EFI shell. History of the echo commandThe echo command started in Multics. Later it was specified by Doug Mcllroy in C language as the "finger exercise" and verified to be helpful. It became a part of the 2 versions of Unix. In the 7 versions, the echo -n command replaced prompt (behaved like the echo command, however, without terminating the output along with the line delimiter). This command began developing C escape sequences like \n along with the difference that the octal escape sequences were represented as the \0ooo rather than \ooo in C on UNIX/PWB and after Unix System 3.The echo command exits in 2 versions on MS-DOS. Nowadays, various echo incompatible implementations are available on distinct operating systems (various on the similar system). By default, a few of them developing escape sequences, a few of them does not. Similarly, a few of them getting options (list of which changing with implementations), and a few of them does not. Echo POSIX Specification leaves the nature unspecified when the initial argument is -n or other arguments include backslash characters during the specification of Unix (option XSI in POSIX) mandates the development of the sequences and doesn't permit the option processing. Several implementations of the echo command are not flexible inside the default platform. Due to these types of changes in nature, the echo command is examined as a non-portable command, and the command, i.e, printf is preferred rather on Unix-like systems. What are the echo control characters?Once we have understood the general principle of the echo command, we will learn the control characters that we can use with the command. These control characters are not visible on our screen directly but determine several things, such as the line breaks, the end of the text, and the beginning of the text.
How can colors be determined using echo?The echo command can be used to define text attributes like colors for the background and font while outputting text. It works by inserting every character in quotes or specifying the colors in several variables to make the string much easier to read. The following is an overview of distinct escape codes for distinct background and font colors:
How do we set text properties with echo?In inclusion to the background and font color, the echo command can be used to define text attributes like underline or boldface. The following are some codes for many text properties:
Displaying a string/text:Syntax: Example: Output: Echo Command OptionsThere are various options available in the echo command. These options are listed and explained below: 1. \b: This option is used for removing every space among the text/string. Example: Output: 2. \c: This option is used for suppressing the trailing new line along with the '-e' backspace interpretor to proceed without emitting any new line. Example: Output: 3. \n: This option is used for creating a new line and this new line will be created from where it's used. Example: Output: 4. \t: This option is used for creating the horizontal tab spaces. Example: Output: 5. \r: This option is used for carriage return along with '-e' backspace interpretor to have described carriage return in the result. Example: Output: 6. \v: This option is used for creating the vertical tab spaces. Example: Output: 7. \a: This option is used for alert return along with '-e' backspace interpretor to add sound alert. Example: Output: This command if run, it will generate a bel or alert sound. Note: Before firing, ensure to check the volume keys.8. echo *: This option is used for printing every folder or file. It is the same as the ls command in Linux. Example: Output: 9. -n: This option is used for omitting echoing trailing new lines. Example: Output: 10. Print "Hello All": For printing text "Hello All!" on the terminal, we can use the below command: Example: Output: 11. Print specific types of files: For example, if we wish to print every '.c' file, we can apply the below command: Example: Output: Next TopicLinux Change or set Password |