shell脚本中的多个echo输出

时间:2013-10-18 06:47:25

标签: shell scripting

我是脚本新手。我希望将输出echo的行数合并到一行:

   echo "$reasult1 \n"
   echo "$reasult2 \n"
   echo "$reasult3 \n"
   echo "$reasult4 \n"
   echo "$reasult5 \n"
   echo "$reasult6 \n"
   echo "$reasult7 \n"
   echo "$reasult8 \n"
   echo "$reasult9 \n"
   echo "$reasult10 \n"

我想要上面的一行。

2 个答案:

答案 0 :(得分:0)

试试这个:

echo $reasult1 $reasult2 $reasult3 ....

答案 1 :(得分:0)

echo的工作方式因shell而异。您可以使用printf代替,这样会更加统一。

# printf does not print a newline by default. If you really want two newlines per
# echo, as implied by your code, add another \n to the format string.
printf "%s\n" "$result1" "$result2" "$result3"

你想要的变量很多。第一个参数中的格式会根据需要重复多次,以消耗所有剩余的参数。

相关问题