Bash: Range of Variables

Range of variables:

In the shell we are dealing with two types of coverage:

  • Local (defined using the local tag);
  • Global (all other parameters except the functions - access to them, it is possibile to the entire script)

The following script demonstrates the use of global and local variables:

#!/bin/bash
function Display ()
{
local local_variable=1024
global_variable_F=32
echo "local_variable has value: $local_variable"
echo "global_variable_F has value: $global_variable_F"
}
echo ": : === I'm going to print"
Display
echo ": : === Outside the function"
echo "local_variable outside function is $local_variable"
echo "global_variable_F outside function is $global_variable_F"


After starting obtain the following result:


: : === I'm going to display
local_variable has a value of: 1024
global_variable_F has the value: 32
: : === Outside the function
local_variable outside a function is:
global_variable_F outside the function is: 32


Local variable in the main program has no value!