【问题标题】:echo in shell script replaces variable with following charactersshell脚本中的echo用以下字符替换变量
【发布时间】:2013-05-19 07:41:36
【问题描述】:

当使用curlawk 获取HTTP 请求的内容长度时,结果变量在用于echo 语句和以下字符时会被“擦除”。

为什么?

#!/bin/sh
CONF_CORE_URL="http://www.google.com/"
CMD_SIZE_TARGET=$(curl -sS -I $CONF_CORE_URL | awk '/Content-Length/ {print $2}')
echo "${CMD_SIZE_TARGET}"
echo "${CMD_SIZE_TARGET} test"
exit 0

预期输出:

222
222 test

实际输出:

222
 test

【问题讨论】:

    标签: http shell curl awk


    【解决方案1】:

    $CMD_SIZE_TARGET 末尾有一个\r,您需要先将其剥离。

    【讨论】:

    • 正确。谢谢伊格纳西奥。一旦允许我(在 10 分钟内),我会接受你的回答。
    猜你喜欢
    • 2012-11-02
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    • 2014-11-24
    • 1970-01-01
    相关资源
    最近更新 更多