DistributedNetworks DistributedNetworks

Shell Components   «Prev 

Variables used within Shell Scripts

Variables within Scripts

  1. System variable to return the Process ID of the script
  2. System variable to return the first command line parameter
  3. User-defined variable for counting in a loop
  4. Environment variable containing the current user’s home directory path
  5. User-defined variable to hold a constant value referenced in the script
  6. environment variable containing the operating system name

Variables in the Bourne shell

Variables in the Bourne shell are more straightforward and homogeneous than in the C shell, and are treated more consistently. There are no special variables that are propagated from shell to environment variables, and vice versa. There is only one command to set a normal variable, and one command to make any variable into an environment variable. In sh, to set a key equal to a value, the syntax is:
prompt$ key=value

Note that it is important that no spaces be included between the variable and the value to which it is being set. To make a variable visible to the environment, it must be "'exported". The shell builtin export is designed for this task.