What Does Shell Variable Mean?
A shell variable is a variable that is available only to the current shell. In contrast, an environment variable is available system wide and can be used by other applications on the system.
A shell is the operating system’s command interpreter. It processes the commands entered on the command line or read from a shell script file.
Techopedia Explains Shell Variable
A variable is a location in memory that is used to hold a value. This location is assigned a name to make it descriptive. The value could be any type of data such as a name, number, text or filename/directory. So, a variable is nothing more than a pointer to a particular data. A shell allows a user to create, assign or delete variables. However, these variables are only temporary and are automatically deleted when the shell session is closed. To make a shell variable persistent and available system wide, it must be exported, thus converting it into an environment variable. The command used for doing this depends on the specific shell being used. In the Bash shell used by Linux, the command is “export”.
A shell variable is created with the following syntax: “variable_name=variable_value”. For example, the command “set COMPUTER_NAME=mercury” creates the shell variable named “COMPUTER_NAME” with a value of “mercury”. For values with spaces, quotation marks must be used. Although not required, the convention in Unix is to use uppercase letters for the variable names. Also, in Unix, variable names, like filenames, are case sensitive.