在shellscript里变量赋值基于卷曲输出 [英] In ShellScript Assign Variable Based on Curl Output

查看:123
本文介绍了在shellscript里变量赋值基于卷曲输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个shellscript里将分配一个变量卷曲输出。当我在命令行中运行这个curl命令的输出是这样的:

I am trying to write a shellscript that will assign a variable to curl output. The output of this curl command when I run it from the command line is this:

$curl "test.test.com/landing/505978290?c=Area%20Rug"
www.test.com/test/test?test=test

去这个网址应该是简单地输出另一个URL文本文档。我想测试,这第二个网址是它应该是URL。

Going to this url is supposed to simply output a text document with another url. I want to test that this second url is the url it is supposed to be.

   url = $(curl "test.test.com/landing/505978290?c=Area%20Rug")
   if [$url -gt "www.tazinga.com/landing/505978290?c=area%20rug&si=gw&alt_css=silver&sv=34&"]         echo ""test.test.com/landing/505978290?c=Area%20Rug did not redirect properly"
    else
        echo "Right URL"
    fi

然而,当我运行shellscript里,我得到这样的输出:

However, when I run the shellscript I get this output:

       % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    75    0    75    0     0    997      0 --:--:-- --:--:-- --:--:--  1013
Command not found. 
-bash: [: missing `]'
yes

如果我尝试打印出URL,我得到一个空字符串。我得到这个无论作为字符串是否正确不匹配与否。为什么卷曲的shellscript里比在命令行中运行不同的

If I try to print out url, I get an empty string. I get this regardless as to whether or not the string correctly matches or not. Why is curl operating differently in a shellscript than from the command line.

推荐答案

有不应该有空格时分配的url,试试这个: -

There should no have spaces when assign url, try this :-

url=$(curl -s ...)

请注意:卷曲-s是燮preSS进度表

note : curl -s is to suppress the progress meter

这篇关于在shellscript里变量赋值基于卷曲输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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