-2

I have the following code:

#!/bin/sh
uname=`awk 'NR>1{print $1}' foo.txt`
echo $uname

If I execute the command awk 'NR>1{print $1}' foo.txt by itself, I get the following format:

abc123
Apple
Test

When I save the command as a variable and echo it, the output becomes:

abc123 Apple Test

How would I go about making sure the output of $uname will be in the first output form listed above?

swam
  • 293
  • 6
  • 19

1 Answers1

4

Simply quote your variable as you ALWAYS should unless you have a specific purpose in mind by leaving it unquoted and fully understand all of the implications:

echo "$uname"

Btw you should use

var=$(cmd)

instead of the deprecated

var=`cmd`
Ed Morton
  • 188,023
  • 17
  • 78
  • 185