functions and variables in bash

I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script.

setup(){

  none=0; low=1; medium=2; high=3; debug=4

  var1="red"
  var2="fred"

}

create_basemap() {
   
 xminBse=$(( $xmin - 2.0 ))   
 xmaxBse=$(( $xmax + 2.0 ))   
 zminBse=$(( $zmin - 2.0 ))     
 zmaxBse=$(( $zmax + 2.0 )) 
  
 xpos=0   
 ypos=0   
 xpos=$xmin   
 ypos=$(( $zmax + 1.5 ))   
 title="Sound speed, c, Mm/min"   
 xDesc="Distance, x, Mm"   
 yDesc="Depth, z, Mm" 
  
 # Scale attributes   xpos=$(( $wtimap + 0.5 ))    
 ypos=$(( $htimap / 2.0 ))   
 sclen=$htimap   scwid=0.4   

 # Create the grid   
 xyz2grd $f.xzc -G$f.grd -I$vdx/$vdz -R$xmin/$xmax/$zmin/$zmax   # Create the color palette   makecpt -C$color -T$cmin/$cmax/0.005 -Z > $f.cpt   

 # Create the basemap    
 wtbmap=$(( $wtimap + 6 ))   
 htbmap=$(( $htimap + 5 ))   
 psbasemap -JX$wtbmap/$htbmap -R0/$wtbmap/0/$htbmap -B0 -K > $f.ps
}

create_contour() {
                           
 textPosx=`echo $xminBse | awk '{print $1 + 1.2}'`   
 textPosy=`echo $zmaxBse | awk '{print $1 - 1.2}'`   
 txt="$textPosx $textPosy 12 0.0 0 BL $fullname"   
 echo $txt | pstext -JX$wtbmap/$htbmap -R$xminBse/$xmaxBse/$zminBse/$zmaxBse -Wwhite -O -K >> $f.ps   
 # Display the image    
 grdimage $f.grd -JX$wtimap/$htimap -R$xmin/$xmax/$zmin/$zmax -C$f.cpt  -B$ax:"$xDesc":/$az:"$yDesc"::."$title":WSne -X2.5 -Y2 -O -K >> $f.ps   

 # Can use units on the contours if needed   
 units="Mm/min"   
 units=""   

 # Annotate contour lines every ${labeldistx} cm   
 contLabelDist=`echo $wtimap | awk '{print $1/2}'`   
 contLabelDist="d${contLabelDist}c"   

 # Include contour lines with annotations   
 grdcontour $f.grd -C$ctc -JX -A$cta+v+u$units -G$contLabelDist -B -R -O -K >> $f.ps  

}

Yes you can, as long as you don't use "local" for the variables (and of course if you call "setup" before other uses of the variable).

That's good. So now I consider the following toy problem. I have two bash scripts as follows

cat colors.bash

#!/bin/bash  

colors() {   
  red="red"  
  blue="blue"   
  green="green" 
} 

car() {
  color_car="$red"
} 

pen() {
  pen_color="$blue"
}
cat property.bash  

source colors.bash  
my_property() {
  echo "$color_car"
}

I want to have the function my_property returning red. My problem is that I do not want to call the function colors inside car before setting

color_car="$red"

Don't call that function, then.

Ok, so I just call colors in my_property, which seems to work

source colors.bash  
my_property() {
  colors
  car
  echo $color_car
 }

---------- Post updated at 04:53 PM ---------- Previous update was at 04:44 PM ----------

My problem is this:

Suppose I have lots of properties which all call colors

pen
car
box
ball
plate

and then I start calling pen and car several times in my_property, this would mean that all colors would be redefined everytime which is a waste

Here is an example

cat colors.bash

#!/bin/bash  

colors() {   
  red="red"  
  blue="blue"   
  green="green" 
} 

car() {
  echo $red
} 

pen() {
   echo $blue
}

ball() {
    echo $blue
 }
 
plate() {
   echo $blue
  }
  
cat property.bash

#!/bin/bash  

my_property() {
  colors

  car
  car
  car
  plate
  echo $red
 
}


As the last line in colors.bash you can call the function colors.

Even if the functions are declared before calling colors?

Yes, the code in the functions are not executed when declaring them.