【问题标题】:multiple echo output in shell scriptshell脚本中的多个回显输出
【发布时间】:2013-10-18 06:47:24
【问题描述】:

我是脚本新手。我想将获取 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"

我想要上面的一行。

【问题讨论】:

  • echo $reasult{1..10}

标签: shell scripting


【解决方案1】:

试试这个:

echo $reasult1 $reasult2 $reasult3 ....

【讨论】:

    【解决方案2】:

    echo 的工作方式因外壳而异。可以改用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"
    

    无论你想要多少变量。第一个参数中的格式会根据需要重复多次以使用所有剩余的参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      • 2020-09-03
      • 1970-01-01
      相关资源
      最近更新 更多