Reputation: 1188
I want to assign a value to a variable (it will be different variables) but I want to use a function to do that, it would be something like "Pass argument by value" as C# do that.
Here is the example what I want to do:
#/bin/ksh
MyVariable=""
ValidateVariableValue()
{
${1}="Working with this!"
}
ValidateVariableValue "MyVariable"
echo "value is: ${MyVariable}"
I want that my function receive the name of the variable and assign a value inside of my function.
That is possible? there's any way to do something similar?
Thanks.
Upvotes: 0
Views: 156
Reputation: 364
You could to like this :
#/bin/ksh
MyVariable=""
function ValidateVariableValue()
{
eval $1="Working with this!"
}
ValidateVariableValue MyVariable
echo "value is: ${MyVariable}"
Upvotes: 2