Here is the way to write the echo command correctly in Linux. The command’s usage is to display the text. When spaces are part of the text, it behaves differently. Below, you will find some examples of how it works.
Echo terminal command
In the command prompt, define a variable with some value. And print the same using the Echo command. The Echo will remove all leading, trailing, and extra spaces in between. It is how it works in the command prompt (terminal). Checkout the top 10 Linux commands you should know.
x= " a b c"
echo $x
the output will be:
a b c

Echo command in the shell-script
In the shell script, you need to double-check for extra spaces. The echo command in shell-script considers those also.
Here for the x1 variable, the value has two spaces. In the output in the calculation, it takes into account extra space.

You can see the result. It displayed a total of 7 characters that included one extra space.

Related
You must be logged in to post a comment.