I have a variable
$myvar that contains two lines, and I want to put first of them into a new variable.
When I try:
$ myvar1 = $(echo $myvar | head -n 1)
It doesn't work because echo doesn't output newlines as I am expecting.
Obviously I can do this:
$ myvar1 = $(echo $myvar | cut -d " " -f 1)
It will work as echo's output contains one word on the first line and one word on the second.
I have two questions:
- Why does echo print spaces instead of line breaks?
- Is it possible to make it easily or more correct (I'm not a professional in shell scripting, maybe I'm missing something here)