Command substitution

In the keyboard, there is one interesting key, the backward quote such as "`". This key is normally situated below the Esc key. If we place text between two successive back quotes, then echo will execute those as commands instead of processing them as plane text.

Alternate syntax for $(command) is the backtick character "`", which we can see as follows:

$(command) or `command`

For example:

  • We need to use proper double quoted inverted commas, as follows:
    $ echo "Hello, whoami"
    
  • The next command will print the text as it is; such as Hello, whoami:
    Hello, whoami
    
  • Use proper double inverted commas:
    $ echo "Hello, `whoami`."
    Hello, student
    

    When we enclose whoami text in the "`" character, the same text which was printed as plain text ...

Get Learning Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.