The correct way to do it would be:
MYVAR1="${MYVAR1}${MYVAR2}"
The braces are usually used when you concatenate variables. Use quotes.
The variable is still local since you reassigned its value within the scope of the function.
An example:
#!/usr/bin/env bash
_myFunction()
{
local var_1="one"
local var_2="two"
local -g var_3="three" # The -g switch makes a local variable a global variable
var_4="four" # This will be global since we didn't mark it as a local variable from the start
var_1="${var_1}${var_2}"
echo "Inside function var_1=${var_1}"
echo "Inside function var_2=${var_2}"
echo "Inside function var_3=${var_3}"
echo "Inside function var_4=${var_4}"
}
_myFunction
echo "Outside function var_1=${var_1}"
echo "Outside function var_2=${var_2}"
echo "Outside function var_3=${var_3}"
echo "Outside function var_4=${var_4}"
This results in:
$ ./script
Inside function var_1=onetwo
Inside function var_2=two
Inside function var_3=three
Inside function var_4=four
Outside function var_1=
Outside function var_2=
Outside function var_3=three
Outside function var_4=four
MYVAR1="$MYVAR1$MYVAR2";