Distributed Networks Distributed Networks





Unix Shell Scripts   «Prev  Next»
Lesson 1

Introduction to working with Variables using Unix Shell

Variables are the part of every script that holds information used by the script. Many different types of variables can be used in a shell script. This module describes how to create and access those variables.
By the end of this module you will be able to:
  1. Access information passed into a shell script on the command line
  2. Use predefined shell and system variables
  3. Access the value of environment variables
  4. Create your own variables
  5. Use different syntax in scripts to access information in variables
  6. Work with string (text) and numeric data stored in variables
  7. Create and use array variables


Shell variables can be divided into two types:
  1. shell environment variables
  2. and user-defined variables.

Environment variables are used to make the environment settings for proper execution of shell commands. Most of these variables are initialized in some of the system setup files. When a user logs in, the system setup files (such as the .profile file) are executed and accomplish the initialization of those environment variables. Usually, the system administrator writes the system setup files to set up a common environment for all users of the system. The users, however, can customize their own shell environment by assigning different values to some or all of these variables in the setup file according to their demands.
When a command is executed as a child process of the login shell, a copy of environment variables is passed to it by the kernel.