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提供的解决方案吗?