【问题标题】:Bash script string expansionBash 脚本字符串扩展
【发布时间】:2013-11-16 10:49:52
【问题描述】:

我目前在 bash 中输入以下命令时遇到问题:

RESPONSE=`curl -k "$line" --cert=\"$certfile:$certpassfile\" --silent --write-out --head '%{http_code}\n'`

其中$line 是url,$certfile 是pem 文件的路径,$certpassfile 是证书密码。

我收到以下错误:

++ curl -k url '--cert="/certpath:certpassword"' --silent --write-out --head '%{http_code}\n'

curl: 选项 --cert="/certpath:certpassword": 未知

当我不在证书文件周围加双引号并且不转义它时,命令如下所示:

RESPONSE=`curl -k "$line" --cert="$certfile:$certpassfile" --silent --write-out --head '%{http_code}\n'`

我收到相同的错误但路径不同:

++ curl -k url --cert=/certpath:certpassword --silent --write-out --head '%{http_code}\n' curl: option --cert=/certpath:certpassword: 未知

知道如何创建命令应该是:

curl -k url --cert="/certpath:certpassword" --silent --write-out --head '%{http_code}\n'

【问题讨论】:

    标签: bash curl scripting


    【解决方案1】:

    我认为你应该去掉 --cert 和值之间的等号:

    RESPONSE=$(curl -k "$line" --cert "$certfile:$certpassfile" \
                    --silent --write-out --head '%{http_code}\n')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 2011-12-19
      • 1970-01-01
      • 2015-07-24
      相关资源
      最近更新 更多