How to embed the output of a command into a bash script.

Posted: February 11, 2017. At: 12:07 PM. This was 6 months ago. Post ID: 10189

Embedding the output of a command into a bash shell script is quite easy.

Here is an example.

echo "Hello $(whoami), the date is $(date -u). Have a nice day"

This is the output this will give you.

┌─[[email protected]]─[~]
└──╼ $echo "Hello $(whoami), the date is $(date -u). Have a nice day."
Hello jason, the date is Saturday 11 February  00:58:10 UTC 2017. Have a nice day.

This way, one-liners may be constructed to output information from a Linux command in one long echo command. This could be very useful.

No comments have been made. Use this form to start the conversation :)

Leave a Reply