gpt4 book ai didi

shell - 在命令行上将密码传递给 curl

转载 作者:行者123 更新时间:2023-12-03 13:51:37 25 4
gpt4 key购买 nike

我有一个要求,我试图编写一个在内部调用 curl 命令的 shell 脚本。我将密码、用户名和 url 作为变量存储在脚本中。但是,由于我想避免在脚本中使用 curl 命令的 user:password 格式,因此我只是使用 curl --user 命令。我的目的是通过标准输入传递密码。所以,我正在尝试这样的事情 -

#!/bin/bash
user="abcuser"
pass="trialrun"
url="https://xyz.abc.com"
curl --user $user $url 2>&1 <<EOF
$pass
EOF

但这行不通。我知道所问的这个问题有多种变化,但我并没有得到确切的答案,因此发布了这个问题。

最佳答案

您可以使用:

curl -u abcuser:trialrun https://xyz.abc.comp

在你的脚本中:
curl -u ${user}:${pass} ${url}

从标准输入读取:
curl  https://xyz.abc.com -K- <<< "-u user:password"

使用时 -K, --config指定 -使 curl 从标准输入读取文件

这应该适用于 HTTP Basic Auth ,来自 curl man:
-u, --user <user:password>

Specify the user name and password to use for server authentication.

关于shell - 在命令行上将密码传递给 curl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46540047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com