Linux Shell Embedding

You can embed new shells on the command line. Means a command line can have a new shell embedded inside it. Variables can be used to prove that new shells have been created.

Syntax:

Example:

Linux Shell Embedding1

Look at the above snapshot, we have embedded a new shell (var-Hyii; echo $var) inside $var. Please note here that $var only exists in the temporary sub shell. It means if you'll try to print it outside the shell then it will display nothing as shown below.


Backticks

We can use backtick instead of dollar bracket to embed in a command line. Backtick can't be used to nest embedded shells.

Example:

Linux Shell Embedding2

Look at the above snapshot, we have embedded 'ls' and 'grep' option in the command line.

Note: grep option is used to search a file matching the specified pattern. We'll learn about it in detail in our further tutorial.


Difference between backtick(`) and single quote(')

Backtick may often confuse with single quote but technically they have significant difference.

Let's see it through an example.

Example:

Linux Shell Embedding3

Look at the above snapshot, backtick embeds the var value in $var. Whereas, single quote simply echo all the text.


Shell Options

There are two options set and unset and both are built-in commands. By default, bash will treat any undefined variable as unbound variable (variable having no value).

set -u option, will treat undefined variables as error.

set +u option, will display nothing.

Linux Shell Embedding4
Next TopicLinux History