Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 我可以在shell脚本中将对象定义为变量吗?_Bash_Shell_Unix - Fatal编程技术网

Bash 我可以在shell脚本中将对象定义为变量吗?

Bash 我可以在shell脚本中将对象定义为变量吗?,bash,shell,unix,Bash,Shell,Unix,我知道如何将字符串存储为变量,例如:API=”http://localhost:4741“ 然而,为了实现CURL请求,我希望能够将对象存储为一个变量,我可以访问对象上的值,比如OBJ=“{name:Joe}”。这可能吗 现在,我的卷曲请求如下所示: curl --include --request POST localhost:3000/scrape \ --header "Content-Type: application/json" \ --data '{ "url": "

我知道如何将字符串存储为变量,例如:
API=”http://localhost:4741“

然而,为了实现CURL请求,我希望能够将对象存储为一个变量,我可以访问对象上的值,比如
OBJ=“{name:Joe}”
。这可能吗

现在,我的卷曲请求如下所示:

curl --include --request POST localhost:3000/scrape \
  --header "Content-Type: application/json" \
  --data '{
    "url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
    "team": "LA Clippers"
  }'
我希望能够使用字典或对象执行类似操作:

TEAM=( ["Clippers"]="http://www.oddsshark.com/stats/gamelog/basketball/nba/20736" )
curl --include --request POST localhost:3000/scrape \
  --header "Content-Type: application/json" \
  --data '{
    "url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
    "team": "${TEAM[Clippers]}"
  }'

将curl请求的输出添加到您的问题中。是否需要工作?您可以。然后使用
jq
解析JSON。见*更新。我尝试了你建议的@0x5453,但没有效果,也许我需要更新我的bash,所以我实际上使用的是zsh而不是bash-这会阻止我使用@0x5453提供的解决方案吗?