gpt4 book ai didi

linux - cURL 中的变量

转载 作者:太空宇宙 更新时间:2023-11-04 11:07:33 24 4
gpt4 key购买 nike

众所周知, token 可以是很长的字符串,一遍又一遍地复制和粘贴会变得很麻烦。

如何将 token 字符串存储为变量并在需要时在 cURL 中调用它

例子

token :“ABCDefG”

我希望能够调用类似的东西:

curl -L --silent --header "Authorization: GoogleLogin auth=${token}"

最佳答案

在 bash 脚本中,您不能将标记放在变量中,如下所示:

#!/bin/bash

token="ABCDef"
curl -L --silent --header "Authorization: GoogleLogin auth=$token"

现在在 bash 脚本中,每当您需要使用 token 时,您只需要使用变量 "$token"(记住用双引号将变量括起来)。

或者你可以设置一个环境变量:

export token=ABCDef

但这不是一个优雅的解决方案

关于linux - cURL 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614744/

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