Concatenate in bash the output of two commands without newline character Concatenate in bash the output of two commands without newline character bash bash

Concatenate in bash the output of two commands without newline character


You can use tr:

{ echo "The quick"; echo "brown fox"; } | tr "\n" " "

OR using sed:

{ echo "The quick"; echo "brown fox"; } | sed ':a;N;s/\n/ /;ba'

OUTPUT:

The quick brown fox 


echo "$(A)" "$(B)"

should work assuming that neither A nor B output multiple lines.

$ echo "$(echo "The quick")" "$(echo "brown fox")"The quick brown fox


$ commandA () { echo "The quick"; }$ commandB () { echo "brown fox"; }$ x="$(commandA) $(commandB)"$ echo "$x"The quick brown fox