I am working in Ubuntu Shell, but i want it to work for UNIX also.
Here is my code:
#!/bin/bash
func()
{
x=42
}
x=9
func
echo $x
- Why is global
x
changed to 42 when i changed only local variablex
- Is in unix different rule for variable scopes?
- Is there a method how to set return value from
func
to global variable, which can be used later in code?
Thank you!