如何解决curl:(6)无法解析主机

时间:2020-06-19 14:19:07

标签: bash curl

我正在尝试使用curl在循环中调用rest api,如下所示。它不起作用并引发错误curl: (6) Couldn't resolve host '$SERVERPROTOCOL:' 但是,如果替换所有环境变量并执行命令,则可以正常工作。

有效的直接命令:

curl -X DELETE -k -H 'Content-Type: application/xml' -H 'Accept: application/xml' -u 'testuser:test123' -i 'https://nonprodhost:443/process/cancel/pvm:0a126'

在循环中卷曲-curl: (6) Couldn't resolve host '$SERVERPROTOCOL:'

for pi in $(cat $halted_pid);do
    # write PID to console so user knows script is working
    echo
    echo "cacnelling process instance - $pi"
    # 2>&1 to include any output on stderr
    curl -X DELETE -k -H 'Content-Type: application/xml' -H 'Accept: application/xml' -u '$USERNAME:USERPASS' -i '$SERVERPROTOCOL://$SERVERHOST:$SERVERPORT/process/cancel/$pi' 2>&1 | tee -a $halted_pi_cancellation_logfile
done

1 个答案:

答案 0 :(得分:1)

为什么我认为问题是单引号?尝试将单引号替换为双引号

(引用:https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

   <li>Group/Leader Selection: The coordinator select the members of the group and chooses one member
       as the leader.</li>

转换为:

curl -X DELETE -k -H 'Content-Type: application/xml' -H 'Accept: application/xml' -u '$USERNAME:USERPASS' -i '$SERVERPROTOCOL://$SERVERHOST:$SERVERPORT/process/cancel/$pi' 2>&1 | tee -a $halted_pi_cancellation_logfile
相关问题