I have a linux bash
script with a function:
myfunctiona ()
{
local MYVAR1="one"
local MYVAR2="two"
echo $MYVAR1
# The line beneath is the line in question!
local MYVAR1=$MYVAR1$MYVAR2
}
When I want to give the LOCAL
variable MYVAR1
in the function myfunctiona
a new value, do I have to write
local MYVAR1=$MYVAR1$MYVAR2
or can I also write
MYVAR1=$MYVAR1$MYVAR2
With the second line without "local" do I create a global variable with the same name?
The correct way to do it would be:
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:
This results in:
Once you've defined a local variable you can assign it normally, like this:
which gives the output:
HTH
You can give this way, but as Ube said for concatenation you need to give like that -
Even this works for concatenation