return value of a function

Hi
I have a doubt in the way the variables inside a function are treated .
if a function is called from the main script directly, the variables inside them act as global variables.
however if the return value of the function is stored to some other variable in the main script as shown,
x=`some_function $some_args`
then all the variables in the function become local ones. they are not relected in the main script.

thnx in advance....

That is because `somefunc somearg` is run in backtics - as a child process. Any changes to variables are not seen in the calling (parent) process.

so why it is not run as a child process when function is called directly in the main script

  1. because that is what shells do. :slight_smile:

  2. It's more useful as so you *can* have functions that change global variables.

  3. It means it does not have to fork() another process to do the job.