Bash Variables

Bash uses two kinds of variables.

  • System Variables: Variables pertaining to the Unix system
  • User Defined Variables: Variables created by users for scripting

To see a list of system variables type:

set

This would give you a list of system variables. DO NOT change values of any of these variable unless you know what you are doing. Unlike Microsoft windows, Linux allows you more control over you system assuming that you know what you are doing. So, if the root granted you a rather unrestrictive access, you can create many problems for yourself.

To create a user defined variable 'number', for example:

number=10

You can use alphanumeric characters and underscore to for variable names. Variable names are case-sensitive. You many not use spaces in assignment. Following are not allowed.

number =10

number= 10

number = 10

To assign NULL values:

budget=""

budget=

To print variables

echo $number

Example

year="427 BC"
name=Plato
city=Athens
echo "$name was born in $city around $year"