Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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
Json 在CURL GET中使用变量_Json_Bash_Curl_Quoting - Fatal编程技术网

Json 在CURL GET中使用变量

Json 在CURL GET中使用变量,json,bash,curl,quoting,Json,Bash,Curl,Quoting,我觉得我只是错过了一些非常愚蠢的东西,没有引用/逃避一些我应该引用的东西,但我已经阅读和测试了很长一段时间了,只是无法让它发挥作用 我有一个包含如下数据的CSV文件: device : 17A3120UAXF-AA002771 account : 9911017093 * About to connect() to www.website.com port 8444 (#0) * Trying 8.8.8.8... * Connected to www.website.com (8.8.8.

我觉得我只是错过了一些非常愚蠢的东西,没有引用/逃避一些我应该引用的东西,但我已经阅读和测试了很长一段时间了,只是无法让它发挥作用

我有一个包含如下数据的CSV文件:

device : 17A3120UAXF-AA002771
account : 9911017093
* About to connect() to www.website.com port 8444 (#0)
*   Trying 8.8.8.8...
* Connected to www.website.com (8.8.8.8) port 8444 (#0)
* Server auth using Basic with user 'username'
> GET /api/subscriber?account=$account HTTP/1.1
> Authorization: Basic madeUpJunkAndNumbers12345==
> User-Agent: curl/7.29.0
> Host: www.website.com:8444
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 404 Not Found
< Content-Type: application/json
< Content-Length: 0
<
* Connection #0 to host www.website.com left intact
^C
测试.csv

17A3120UAXF-AA002771,9911017093
S150Y52157201,9911008933
17A3120UAXF-AA004545,9911016519
S170Y13084226,9911024365
S160Y45021270,9911018486
对于脚本的第一部分,我需要读取第二个变量(即以“99110…”开头的项目)

我正在将这些数据解析为一个CURL while循环,以对文件中的所有行进行排序。此时,我的bash脚本如下所示:

#!/bin/bash

while IFS=, read -r device account; do
echo "device : $device"
echo "account : $account"
curl -X GET --header "Content-Type: application/json" --user username:password --verbose 'https://www.website.com:8444/api/subscriber?account=$account'
done < TESTING.csv
#/bin/bash
当IFS=,read-r设备帐户;做
echo“设备:$device”
echo“账户:$account”
curl-xget--header“Content-Type:application/json”--用户用户名:密码--verbose'https://www.website.com:8444/api/subscriber?account=$account'
完成
我遇到的问题是,虽然“echo”语句能够正确地拉/显示我想要传递的变量,但没有将相同的信息传递到CURL命令中。当我运行脚本时,输出如下所示:

device : 17A3120UAXF-AA002771
account : 9911017093
* About to connect() to www.website.com port 8444 (#0)
*   Trying 8.8.8.8...
* Connected to www.website.com (8.8.8.8) port 8444 (#0)
* Server auth using Basic with user 'username'
> GET /api/subscriber?account=$account HTTP/1.1
> Authorization: Basic madeUpJunkAndNumbers12345==
> User-Agent: curl/7.29.0
> Host: www.website.com:8444
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 404 Not Found
< Content-Type: application/json
< Content-Length: 0
<
* Connection #0 to host www.website.com left intact
^C
设备:17A3120UAXF-AA002771
账户:9911017093
*即将连接()到www.website.com端口8444(#0)
*正在尝试8.8.8.8。。。
*已连接到www.website.com(8.8.8.8)端口8444(#0)
*使用用户“用户名”的Basic进行服务器身份验证
>GET/api/subscriber?account=$account HTTP/1.1
>授权:基本Madeupjunkand号码12345==
>用户代理:curl/7.29.0
>主持人:www.website.com:8444
>接受:*/*
>内容类型:application/json
>
未找到
您在URL中使用单引号,因此变量不会展开。使用双引号:

curl -X GET --header "Content-Type: application/json" --user username:password --verbose "https://www.website.com:8444/api/subscriber?account=$account"

在URL中使用单引号,因此变量不会展开。使用双引号:

curl -X GET --header "Content-Type: application/json" --user username:password --verbose "https://www.website.com:8444/api/subscriber?account=$account"

我想它在这里https://www.website.com:8444/api/subscriber?account=$account'
更改为
请参见:我想它在这里
”https://www.website.com:8444/api/subscriber?account=$account'
更改为
请参阅:感谢您回答Poshi!我以前试过,现在重新测试,它抛出了一个curl错误:设备:17A3120UAXF-AA002771帐户:9911017093*在URL中找到非法字符*关闭连接-1 curl:(3)在URL中找到非法字符^C@Drew这绝对是答案。尝试检查csv文件中是否有不可打印的字符。此外,您还可以使用带有双引号的curl输出更新您的问题“在URL中找到非法字符”表示URL中有CR或LF字符。不过,Modern curl已经改变了这种错误报告……正如其他人告诉您的,您的URL有问题。检查它的字符,包括不可打印的,CR,LF…啊,确实是字符隐藏。这是一个直接来自Windows Excel的CSV文件。我做了一个“tr-d'\r'TESTING_FIXED.csv”,然后用双引号重新运行,它通过了我期望的方式。谢谢你的帮助!谢谢你回答波喜!我以前试过,现在重新测试,它抛出了一个curl错误:设备:17A3120UAXF-AA002771帐户:9911017093*在URL中找到非法字符*关闭连接-1 curl:(3)在URL中找到非法字符^C@Drew这绝对是答案。尝试检查csv文件中是否有不可打印的字符。此外,您还可以使用带有双引号的curl输出更新您的问题“在URL中找到非法字符”表示URL中有CR或LF字符。不过,Modern curl已经改变了这种错误报告……正如其他人告诉您的,您的URL有问题。检查它的字符,包括不可打印的,CR,LF…啊,确实是字符隐藏。这是一个直接来自Windows Excel的CSV文件。我做了一个“tr-d'\r'TESTING_FIXED.csv”,然后用双引号重新运行,它通过了我期望的方式。谢谢你的帮助!