shell script, why isn't if printing message?

Why isn't printing message?

  1 #!/bin/sh
  2
  3 something(){
  4     echo "Inside something"
  5     echo $1 $2
  6 }
  7 val=$(something "Hello " "world")

But it prints.

  1 #!/bin/sh
  2
  3 something(){
  4     echo "Inside something"
  5     echo $1 $2
  6 }
  7 val=$(something "Hello " "world")
  8 echo $val

I don't see any error's :wink:

# cat script.sh
#!/bin/sh

something(){
    echo "Inside something"
    echo $1 $2
}
val=$(something "Hello " "world")
echo "$val"

# ./script.sh
Inside something
Hello world

Yes there is no error.
But the script bellow doesn't display anything.Why?

  1 #!/bin/sh
  2
  3 something(){
  4     echo "Inside something"
  5     echo $1 $2
  6 }
  7 val=$(something "Hello " "world")

Why should it? You never tell it to. The echos in your function get captured by $(...), and whatever they printed is saved to val.

Bump.