The local variable and its scope

In the current shell, we can create and store user-defined variables. These may contain characters, digits, and _. A variable should not start with a digit. Normally, for environment variables, uppercase characters are used.

If we create a new variable, it will not be available in the subshells. The newly created variable will be available only in the current shell. If we run a Shell script, then the local variables will not be available in the commands called by the Shell script. Shell has one special variable, $$. This variable contains the process ID of the current shell.

Let's try a few commands:

This is the process ID of the current shell:

$ echo $$1234

We declare the variable name and initialize it: ...

Get Learning Linux Shell Scripting - Second Edition 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.