Why on earth is the output (really, the last line) of:
num=$(redis-cli info | grep instantaneous_ops_per_sec | cut -d : -f 2)
echo num $num
echo ts $ts
echo "$ns $num"
echo "$ns $num $ts"
The output of
redis-cli ends with a CRLF, but only the LF is stripped by the command substitution. The CR, when output to the terminal, moves the cursor to the beginning of the line. You don't notice that when
$num is the last thing output on a line, but in your last case, the space and value of
$ts are written on top of the previous data.
The easiest way to fix this is to simply trim any trailing CR from the value of