Lesson 11
Shell Scripts Variable Conclusion
This module described the many types of variables that can be used in shell scripts and how you can access or create each type. You learned about variable substitution to get exactly the value you want within a script, and how to work with text strings and numbers that are stored in variables.
Concepts, commands, and Syntax
In this module you learned about these concepts, commands, and syntax styles:
- System variables for accessing predefined system information
- Positional variables for accessing information on the command line
export
to make a variable available to other shells
unset
to make a variable cease to exist
$variablename
to refer to the value of a variable
${variablename}
to refer to the value of a variable more precisely
- Strings can be stored in shell variables, but few string manipulations are easily done in shell scripts
- Numbers can be stored in shell variables, but an external command must be used for any calculations.
- Array variables are not supported in the Bourne shell but can be used in later shells such as ksh, bash, and tcsh.
Linux Shell Scripting
Primitive System Data Types
Historically, certain C data types have been associated with certain UNIX system variables.
For example, major and minor device numbers have historically been stored in a 16-bit short integer, with 8 bits for the major device number and 8 bits for the minor device number.
But many larger systems need more than 256 values for these device numbers, so a different technique is needed.
(Indeed, the 32-bit version of Solaris uses 32 bits for the device number: 14 bits for the major and 18 bits for the minor.)
The header < sys/types.h > defines some implementation-dependent data types, called the primitive system data types.
More of these data types are defined in other headers as well.
These data types are defined in the headers with the C typedef facility and most end in _t.
By defining these data types this way, we do not build into our programs implementation details that can change from one system to another.
We describe what each of these data types is used for when we encounter them later in the text.
Using- Array Variables - Exercise
Click the Exercise link below to review what you have learned about variables.
Using Array Variables - Exercise
The next module describes some methods of good shell script design, such as planning your script in advance and using error-checking commands.