How to add the output of a command when echoing text with bash.

Posted: November 26, 2013. At: 8:16 AM. This was 4 years ago. Post ID: 6602
Page permalink: http://securitronlinux.com/bejiitaswrath/how-to-add-the-output-of-a-command-when-echoing-text-with-bash/

This is how to do this; just add the backticks and you may then echo the output of the logname command in this echo string.

echo "Hello `logname`, this is a nice day is it not?"

This will add the output of the command by executing it and showing the output.

Here we are showing the content of an environment variable.

[email protected]:~$ echo "Hello ${LOGNAME}, this is a nice day is it not?"
Hello homer, this is a nice day is it not?

This is the environment variable value in capitals.

[email protected]:~$ echo "Hello ${LOGNAME^^}, this is a nice day is it not?"
Hello HOMER, this is a nice day is it not?

And with the first letter capitalized.

[email protected]:~$ echo "Hello ${LOGNAME^}, this is a nice day is it not?"
Hello Homer, this is a nice day is it not?

This command is printing the kernel version.

[email protected]:~$ echo "This is the kernel release: `uname -r`"
This is the kernel release: 3.12.0-3-generic

These tips are very useful when you are writing a shell script. See what you can do with this!

1 responses to “How to add the output of a command when echoing text with bash.

Leave a Reply