How to echo text and execute a command on the same line?

By | May 6, 2021

In terminal, we can use the echo keyword to display text like this:

echo "Hello World"

and you will get the following:

You can also run a command like:

yarn -v

which produces the following:

If you want to echo and have a command execute and then the results displayed on the same line you have to do this:

echo "My current yarn version is:" : `yarn -v`

The result will be:

The secret is the backtick symbol, also known as left quote, acute or grave accent, back quote… the list goes on.

Leave a Reply

Your email address will not be published. Required fields are marked *