shell script, echo doesn't work

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

Output expected:

Inside somethingHello world

But it's not echoing.

$ cat test
  #!/bin/bash
  something(){
      echo "Inside something"
      echo $1 $2
  }
  val=$(something "Hello " "world")
  echo $val

$ ./test
Inside something Hello world

What is the problem ?

val=$(something "Hello " "world")

This ate away everything ... $( .. made something being executed like any other prg with two parameters. and val got it ... So when you do echo $val ... it shows up ..

This would be better because there are two lines inside $val

echo "${val}"

Inside something
Hello world

To get the expected output the echo inside the loop must not output a line-feed.

Assumin a normal echo (not the one with the -n switch).

echo "Inside something\c"

You do get the expected output with just "echo $val" but this is bad practice.

There is no such thing as a normal echo. There are two major flavours of echo, one which takes the -n option to suppress a trailing newline and the other which uses \c for the same purpose.

There are even versions which accept both forms.

That's why the use of echo is deprecated in favour of printf.