Basic Shell Scripting: Chapter-III

Shell Script Variables:

Variable in shell script means, referencing a numeric or character value. We can access the value of a variable, prefix it with a dollar sign. eg:

Here the variable name is “value “. We can access it’s value by writing $value.

Example 1:

Storing character value in a variable

Example 2:

Storing numeric value in a variable

Arguments and Other Variables:

Arguments are the values we are passing to a shell script. Each value after the script in the command line will be assigned to a special variables like $1, $2, $3 and so on. The name of the script will be store in the variable $0.

The above are some special variables in shell script.

Example 3:

Usage:

Output:

Read-Only Variables:

The shell provides a way to mark the variables are read-only. If a variable will set are read-only then it’s value can’t be change.

This will produce result as below:

Unsetting Variables:

Unsetting or deleting a variable tells the shell to remove the variable from the list of variables that it tracks. Once you unset a variable, you would not be able to access stored value in the variable.

The above script would not print anything.

Previous Chapter

Next Chapter

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

Leave a Reply