Allocate Version Numbers With Bash
Bash at it&squo;s simplest form is a program that runs other programs for you based on input. Bash also has some other features than this such as the ability to store and retrieve variables stored in the Environment for a shell. If you invoke bash and then exit, you will loose the Environment that was set inside the script unless some special things are done.
Allocate Version Numbers With Bash – Details
Bash doesn&squo;t really have a non-volatile storage methodology as far as I know unless one counts file storage, so if we want to be storing a version number somewhere, it will most likely be in a file in some form. For our example, I will be using the name of the file to stor the information and will parse it out later.
Setting and retrieving variables
To set a variable in bash, it is as simple as typeing the following in a script or at the command line.
VAR="Some Var"
To retrieve the variable or check its contents, you can simply use the echo command.
echo $VAR
To store an array, your command should look something like the following:
VARARRAY=(`echo "1 2 3 4"`);
To retrieve the whole array you may use the echo command with a slightly revised syntax
echo ${VARARRAY[*]}
To retrieve a single element, you may use the echo command with the index of the item entered in the square braces
echo ${VARARRAY[1]}
To do some numeric addition, we can perform the following on a variable
VARIABLE=100 echo $[VARIABLE +1]
or
LET VARIABLE=VARIABLE+1