Unix - Shell Variables

Unix shell variables are like containers that store values, such as numbers or text, which can be referenced and manipulated in a shell script or on the command line. These variables are denoted by a dollar sign ($) followed by the variable name.

There are different types of shell variables in Unix, such as environment variables, local variables, and positional parameters.

Environment variables: These are system-wide variables that are used to set system-wide settings, such as the PATH variable, which specifies the directories where the system looks for executable files.

Local variables: These are variables that are created and used within a script or a function. They are not visible outside the script or function.

Positional parameters: These are variables that hold the arguments passed to a shell script or a function. The first argument is stored in the variable $1, the second argument in $2, and so on.

Shell variables can be set, modified, and unset using the built-in commands like ‘export’, ‘unset’, ‘read’, etc. They can also be used to store and manipulate values for various purposes, such as storing user input, performing calculations, and passing values between scripts and functions.