What is the usage of echo -e in Linux?
In Linux, the command ‘echo -e’ is used to output text with escape characters. The ‘-e’ option enables the processing of escape characters. Here are some common uses of ‘echo -e’:
- Output plain text:
- “Hello World” is said.
- Output text with escape characters.
- Print the words “Hello” and “World” separated by a tab.
- In the above example, the “\t” represents a tab character, which will be inserted between “Hello” and “World” when displayed.
- Output text with newline characters:
- Print “Hello” and then “World” on separate lines.
- In the example above, \n represents a line break, which will display “Hello” and “World” on two separate lines when outputted.
- Output text with additional escape characters:
- print “Hello\bWorld”
- In the example above, \b represents the backspace character, deleting the previous character “o” when output, resulting in “HellWorld”.
It’s worth noting that some shells may have different levels of support for “echo -e”, with some shells not enabling escape character processing by default. In such cases, alternative methods should be used to achieve similar effects.