Shell Script Help 1

Hi,

As I came from other programming languages, I had written this small code for learning purpose:

#!/bin/sh

function greet()
{
    msg=$1
    echo In function Greet
    echo Hello $msg
}

ret=$(greet ' World')
echo $ret
echo In Main Program
echo $ret

In the above code, When I run .... it gives me the output:
In function Greet Hello World
In Main Program
In function Greet Hello World

But actually, I want only "Hello World" in the $ret variable. As I know that if you want to return some data from the function you have to write echo statement.
Here there are 2 echo statements in function, one merely prints a just a simple statement and one do some processing.

Then how to get only "Hello World" in ret variable?

Help !!

 echo In function Greet >&2

The variable gets every echo statement to stdout of your function, echo other lines to stderr:

#!/bin/sh

function greet
{
    msg=$1
    echo In function Greet 1>&2
    echo Hello $msg
}

ret=$(greet ' World')
echo $ret
echo In Main Program
echo $ret

thanks for that.

What does >&2 means?

Also, I tried out ..... and it works.

Awesome .... thanks again

As Franklin52 says:

It directs standard output to standard error for that command.