变量在Linux中的curl命令内未扩展 [英] Variable not expanding inside curl command in linux

查看:50
本文介绍了变量在Linux中的curl命令内未扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个curl命令,我想从shell脚本中执行.我的脚本如下:

I have a curl command which I want to execute from inside a shell script. My script is as below:

iddn="`jq -r '.APPID_DN' /scr/resp.json`"
appid = `echo "$iddn" | awk -F',' '{print $1}'`
id =`echo $appid | awk '{print substr($0,4)}'`
apppwd = `jq -r '.APPID_PWD' /scr/resp.json`
tnname = `jq '.tnName' /scr/resp.json`

curl -i --user "$id":"$apppwd" -H "Content-Type: application/xml" -H "Accept: application/xml" -H "X-USER-IDENTITY-DOMAIN-NAME: tn11" --request GET "http://hostname.XX.XXXX.com:port/XXX/services/rest/version/auth/administrator/Clients"

但是我遇到了错误HTTP/1.1 401未经授权未经授权.提供授权标题.

But I am getting below error HTTP/1.1 401 Unauthorized Not authorized. Provide Authorization Header.

我通过回显命令来尝试查看curl命令的形成方式,我得到的是(用户ID和passwd根本没有通过),

I tried by echoing the command to see how the curl command is forming,I am getting it as(userid and passwd not passed at all),

curl -i --user  -H "Content-Type: application/xml" -H "Accept: application/xml" -H "X-USER-IDENTITY-DOMAIN-NAME: tn11" --request GET "http://hostname.XX.XXXX.com:port/XXX/services/rest/version/auth/administrator/Clients"

但是,如果我直接从命令行运行同一命令,它运行正常.请对此提供帮助.

But if i am running the same command directly from command line,its running fine.Please help on this.

关于,Shilpi

推荐答案

id =`echo $appid | awk '{print substr($0,4)}'`
apppwd = `jq -r '.APPID_PWD' /scr/resp.json`

在外壳程序变量分配中,不得在 = 周围放置空格.

You must not put spaces around = in a shell variable assignment.

这篇关于变量在Linux中的curl命令内未扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆