Bash is one of the rare languages that has dynamic scoping (unlike the usual lexical scoping). That means that functions are accessing variables from the last scope they were defined in (that might be an assignment or a declaration with declare or local).
For example:
#!/bin/bash
fun() {
x="newval"
}
x=start
echo "$x"
fun
echo "$x"
Will print:
start
newval
This simple example looks like x is a simple global variable, but it's more than that (scopes are dynamically nested, always the last/previous scope is accessed).
So, if you want to change the variable in your function, just change it.
#!/bin/bash
change_string() {
myString+=",Hello2"
}
myString="Hello1"
change_string $myString
echo "Main: $myString"
You can even change the variable "by reference", if you pass the name of the variable, then use declare -g to set (in outer scope) the value of a variable whose name we know (varname) by appending a text to the current value (accessed via indirect expansion):
change_string() {
varname="$1"
declare -g "$varname"="${!varname},Hello2"
}
myString="Hello1"
change_string myString
# myString is now "Hello1,Hello2"