LINUX

By Using the Linux Echo Command How to Output Text to the Screen

maxresdefault (3)
maxresdefault (3)
Used on its very own in the terminal the echo command isn't in particular beneficial but when used as part of the script it may be used to show commands

This manual will show you how to output textual content to the terminal window the use of the linux echo command.

Used on its very own in the terminal the echo command isn’t in particular beneficial but when used as part of the script it may be used to show commands, errors, and notifications.

Example uses of the linux echo command

In its simplest shape the perfect manner to output textual content to the terminal is as follows:

Echo "howdy world"

The above command outputs the words “howdy global” to the screen (minus the citation marks).

By default, the echo announcement outputs a new line character on the give up of the string.

To test this out attempt the subsequent statement in a terminal window:

Echo "howdy international" && echo "good-bye world"

You may see that the result is as follows:

Hi there international

Good-bye international

You could omit the brand new line man or woman by using adding the minus n switch (-n) as follows:

Echo -n "good day international " && echo -n "good-bye world"

The result from the above command is as follows:

Hiya world goodbye international

Some other issue to consider whilst the use of the echo declaration is the way it handles unique characters.

As an example strive out the following in a terminal window:

Echo "howdy worldrngoodbye world"

In a perfect global the r and n might act as special characters to add a brand new line however they don’t. The end result is as follows:

Howdy worldrngoodbye global

You may enable special characters the use of the echo command by using which includes the -e transfer as follows:

Echo -e "hiya worldrngoodbye global"

This time the end result will be as follows:

Hi there international

Goodbye world

You can of route be in the situation wherein you are attempting to output a string that would be dealt with as a unique individual and you do not want it to. On this situation use a capital e as follows:

Echo -e "hi there worldrngoodbye international"

Which special characters are handled using the -e transfer?

  • \\ backslash
  • \A alert
  • \B backspace
  • \C produce no in addition output
  • \Eescape
  • \F shape feed
  • \N new line
  • \R carriage return
  • \T horizontal tab
  • \V vertical tab
  • \0nnn octal fee with 1 to a few digits
  • \xHH byte with hexadecimal value
READ  10 Best Terminal Emulators for Linux

Permit’s try a couple of these out. Run the subsequent command in a terminal:

Echo -e "helblo world"

The above command would output the following:

Hello international

Obviously now not genuinely what you will want to output to the display screen however you get the factor that backslash b gets rid of the previous letter.

Now strive the following in a terminal window:

Echo -e "hello\c international"

This command outputs the whole thing up until the backslash and c. The whole thing else is unnoticed together with the brand new line.

So what is the distinction between a new line person and a carriage return? The brand new line character actions the cursor down to the next line while the carriage return moves the cursor back to the left aspect.

For example input the subsequent into your terminal window:

Echo -e "hello\nworld"

The output of the above command places the two phrases on exceptional traces:

hello

World

Now strive the subsequent out in a terminal window:

Echo -e "hello\rworld"

The distinction among a new line and carriage return turns into very apparent as the subsequent can be displayed as an output:

World

The word hello turned into displayed, the carriage go back took the cursor to the start of the line and the phrase global become displayed.

It will become a little more apparent in case you attempt the following:

Echo -e "hello\rhi"

The output from the above is as follows:

Hillo

In reality the use of many people still use the rn notation whilst outputting to a new line. Pretty often, but, you may break out with just a n.​

READ  How To Install Oracle Java 8 in Ubuntu 16.04

 

About the author

Venkatesan Prabu

Venkatesan Prabu

Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.

Add Comment

Click here to post a comment