Spe*_*cer 1 linux bash shell curl
我正在尝试编写一个shellcript,它将为curl输出分配一个变量.从命令行运行时,此curl命令的输出如下:
$curl "test.test.com/landing/505978290?c=Area%20Rug"
www.test.com/test/test?test=test
Run Code Online (Sandbox Code Playgroud)
去这个网址应该只是输出一个文本文档与另一个网址.我想测试第二个url是它应该是的url.
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
Run Code Online (Sandbox Code Playgroud)
但是,当我运行shellscript时,我得到了这个输出:
% 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
Run Code Online (Sandbox Code Playgroud)
如果我尝试打印出url,我会得到一个空字符串.无论字符串是否正确匹配,我都会得到这个.为什么curl在shellcript中的操作方式与命令行不同.