Linux Curl bash脚本被截断/合并

Linux Curl bash脚本被截断/合并,linux,bash,curl,Linux,Bash,Curl,我的目标是让bash脚本从webapi获取一个令牌,并将该令牌解析为post命令,该命令将在该webapi上创建一个新帐户(基于用户输入)。它成功地获取了令牌,但当我在POST命令中引用变量时,它要么将其切断,要么将其合并到选项卡中。以前有人见过这种情况吗 我读过一个类似的问题,问题是内容标题,我已经删除了它,但它没有修复这个问题 警告…我是一个学习者,所以我的代码不是最好的 我的bash脚本: #!/bin/bash curl --insecure -X POST \ https://1

我的目标是让bash脚本从webapi获取一个令牌,并将该令牌解析为post命令,该命令将在该webapi上创建一个新帐户(基于用户输入)。它成功地获取了令牌,但当我在POST命令中引用变量时,它要么将其切断,要么将其合并到选项卡中。以前有人见过这种情况吗

我读过一个类似的问题,问题是内容标题,我已经删除了它,但它没有修复这个问题

警告…我是一个学习者,所以我的代码不是最好的

我的bash脚本:

#!/bin/bash

curl --insecure -X POST \
  https://192.168.XX.XXX:8443/application/token \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/xml' \
  -H 'Host: 192.168.XX.XX:8443' \
  -H 'cache-control: no-cache' \
  -H 'client-key: 123' \
  -H 'client-name: 1234' \
  -H 'client-secret: 123456' \
  -H 'grant_type: OAuth' \
  -d '<request>
    <username>johndoe</username>
    <password>secret</password>
</request>' > tokenNewAcc.xml

grep 'access_token' tokenNewAcc.xml | sed 's/.*://' | sed s/,// |  tr -d '"' > /home/oracle/tokenNewAcc.txt

rm tokenNewAcc.xml

value=`cat /home/oracle/tokenNewAcc.txt`

MYVAR=`cat /home/oracle/testaccounts.txt`

ID=`cut -d' ' -f1  /home/oracle/testaccounts.txt`
FNAME=`cut -d' ' -f2  /home/oracle/testaccounts.txt`
LNAME=`cut -d' ' -f3 /home/oracle/testaccounts.txt`
EMAIL=`cut -d' ' -f4  /home/oracle/testaccounts.txt`L
\

curl -k -X POST \
  https://192.168.XX.XXX:8443/application/accounts \
  -H 'Accept: */*' \
  -H 'Content-Type: application/xml' \
  -H 'Host: 192.168.XX.XXX:8443' \
  -H "auth: "$value"" \
  -H 'cache-control: no-cache' \
  -d '<request>
<userid'$ID'</userid>
<firstname>'$FNAME'</firstname>
<lastname>'$LNAME'</lastname>
<email>'$EMAIL'</email>
</request>'


OUTPUT of POST where it has trouble:

curl -k -X POST https://192.168.36.XXX:8443/cloudminder/accounts -H 'Accept: */*' -H 'Content-Type: application/xml' -H 'Host: 192.168.36.1' -H 'cache-control: no-cache' -d '<request>ad9f23295b6
<useridconnectortest</userid>
<firstname>conn</firstname>
<lastname>connect</lastname>
<email>connectorL</email>
</request>'
#/bin/bash
卷曲-不安全-X柱\
https://192.168.XX.XXX:8443/application/token \
-H'接受:*/*'\
-H'接受编码:gzip,deflate'\
-H'缓存控制:无缓存'\
-H'连接:保持活力'\
-H'内容类型:应用程序/xml'\
-H'主机:192.168.XX.XX:8443'\
-H'缓存控制:无缓存'\
-H'客户端密钥:123'\
-H'客户名称:1234'\
-H'客户机密:123456'\
-H'grant_类型:OAuth'\
-d'
约翰多
秘密
'>tokenNewAcc.xml
grep'access_token'tokenNewAcc.xml | sed's/*://'| sed s/,//| tr-d'>/home/oracle/tokenNewAcc.txt
rm tokenNewAcc.xml
value=`cat/home/oracle/tokenNewAcc.txt`
MYVAR=`cat/home/oracle/testaccounts.txt`
ID=`cut-d'-f1/home/oracle/testaccounts.txt`
FNAME=`cut-d'-f2/home/oracle/testaccounts.txt`
LNAME=`cut-d'-f3/home/oracle/testaccounts.txt`
EMAIL=`cut-d'-f4/home/oracle/testaccounts.txt`L
\
curl-k-X柱\
https://192.168.XX.XXX:8443/application/accounts \
-H'接受:*/*'\
-H'内容类型:应用程序/xml'\
-H'主机:192.168.XX.XXX:8443'\
-H“身份验证:$value”\
-H'缓存控制:无缓存'\
-d'

您的引用样式很奇怪,可能是问题的一部分。当您需要展开变量时,请使用
“text$variable text”
,尤其是
:使用未引用的变量(例如
'text'$variable'text'
)如果变量扩展为包含空格、制表符或换行符的内容,则可能会导致单词分裂。
“auth:$value”“
可能应该是
“auth:\$value\”“
如果需要在值周围加上双引号。此外,您可能需要检查
$value
和/或提取请求部分的文件以获取控制字符。例如,您可以使用
xxd
检查字符串的十六进制内容,以确保它们不包含隐藏字符,例如
\r
,这可能解释您的奇怪行为(例如字符串“foo\rbar”将显示为“bar”)因为
\r
使您在继续写之前返回到行首)