Shell Variable

Why Trust Techopedia

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.

Advertisements

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.

Advertisements

Related Terms

Margaret Rouse
Technology Expert
Margaret Rouse
Technology Expert

Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.