i have a script like this
#!/bin/ksh
initialize()
{
x=20
}
...
...
...
x=10
initialize;
echo $x
when i try to echo the value of x it should return only 10 and not 20
how to achieve the same
can any one help
thanks in advance
i have a script like this
#!/bin/ksh
initialize()
{
x=20
}
...
...
...
x=10
initialize;
echo $x
when i try to echo the value of x it should return only 10 and not 20
how to achieve the same
can any one help
thanks in advance
Declare x as local using the local keyword inside the function to prevent it from modifying the global variable.
local x=20
A variable declared as local is one that is visible only within the block of code in which it appears. It has local "scope." In a function, a local variable has meaning only within that function block.