How do I delete all text after a newline character in bash?

advertisements

Suppose I have a Bash object $TEST defined like this:

> TEST=`echo -e "hello\\nworld"`
> echo $TEST
hello
world

Using just echo, how do I output 'hello' from $TEST? How do I output 'world' from TEST? (no other commands allowed). I have trouble getting it to recognize the newline character.


Using bash parameter expansion:

$ echo "$TEST"
hello
world

$ echo "${TEST%$'\n'*}"
hello

$ echo "${TEST#*$'\n'}"
world