Bash script string expansion

给你一囗甜甜゛ 提交于 2019-12-25 00:42:49

问题


I am having an issue with the entering the following command in bash at the moment:

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

where $line is the url, $certfile is the path to the pem file, $certpassfile is the certificate password.

I am getting the following error:

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

curl: option --cert="/certpath:certpassword": is unknown

When i don't double the quotation marks around the certificate file and don't escape it, so the command looks like the below:

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

I receive the same error but a different path:

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

Any idea how I can create the command at it should be which is:

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

回答1:


I think you just should strip that equal sign between --cert and the value:

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


来源:https://stackoverflow.com/questions/19791095/bash-script-string-expansion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!