答案1
双引号变量
echo "${top}"
分配后尝试top="$(top -n1)"
答案2
无法复制:
$ t="$( top -b -n1 )"
$ echo "$t" | head -n3
top - 14:49:52 up 243 days, 17:18, 2 users, load average: 0.03, 0.07, 0.12
Tasks: 205 total, 1 running, 203 sleeping, 1 stopped, 0 zombie
%Cpu(s): 2.4 us, 0.5 sy, 0.1 ni, 96.4 id, 0.7 wa, 0.0 hi, 0.0 si, 0.0 st