In bourne shell I have the following:
VALUES=`some command that returns multiple line values`
echo $VALUES
Looks like:
"ONE"
"TWO"
"THREE"
"FOUR"
I would like it to look like:
"ONE" "TWO" "THREE" "FOUR"
Can anyone help?
If you are using bash , you can use Parameter Expansion: dt=${dt//$'\n'/} # Remove all newlines. dt=${dt%$'\n'} # Remove a trailing newline.
echo $VALUES | tr '\n' ' '
Another method, if you want to not just print out your code but assign it to a variable, and not have a spurious space at the end:
$ var=$(tail -1 /etc/passwd; tail -1 /etc/passwd)
$ echo "$var"
apache:x:48:48:Apache:/var/www:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
$ var=$(echo $var)
$ echo "$var"
apache:x:48:48:Apache:/var/www:/sbin/nologin apache:x:48:48:Apache:/var/www:/sbin/nologin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With