0

when I am doing this

echo -e "hello\nworld"

the result is like this

hello
world

But, Here I am trying to store the shell command result into a variable and I am trying to reuse that variable, like this

output=$(echo -e "hello\nworld")
echo $output

then the result is like this

hello world

But, I am expecting a result like the first one, printed in two lines. How to achieve this?

codeforester
  • 39,467
  • 16
  • 112
  • 140
Robert
  • 67
  • 5
  • *word-splitting* can be your friend or enemy. Try this `(IFS=; output=$(echo -e "hello\nworld"); echo $output)` -- include the `(..)` so it runs in a subshell to prevent changing `IFS` (*Internal Field Separator*) for your current shell. Of course quoting `echo "$output"` will also do. – David C. Rankin Oct 20 '17 at 06:05
  • @DavidC.Rankin Why would you ever do that when you can just quote `$()`. – 123 Oct 20 '17 at 06:43

0 Answers0