leestretton.com

You are in: > Home > Developers Guides

Shell Scripting - Variables

Values of shell variable are all character-based: A value is formally defined to be a list of zero or more elements, and an element is formally defined to be a character string. In other words, a shell variable consists of an array of strings.

For example,

set X

will set the variable $X to have an empty list as its value. The command

set V = abc

will set V to have the string `abc' as its value. The command

set V = (123 def ghi)

will set V to a list of three elements, which are the strings `123', `def' and `ghi'.

The several elements of a list can be treated like array elements. Thus for V in the last example above, $V[2] is the string `def'. We could change it, say to `abc', by the command

set V[2] = abc

In shell scripts variables can be set without the use of the set command. for example:

V=abc

Would set the variable V, which can be accessed with $V to be equal to the string 'abc'. Please note that there are no spaces in between the variable name, V, the = sign and the variable value

Problem with this page? Let us know
© Lee Stretton 2005 | powered by linux powered by php 5 powered by MySQL download rss feeds powered by php 5 valid css