我最近学习了如何在shell中编程。
我无法理解为什么这两个陈述产生不同的输出。似乎没有空格,test将10==11
视为字符串并始终返回true。
$test 10==11 && echo yes || echo no
$yes
$test 10 == 11 && echo yes || echo no
$no
答案 0 :(得分:0)
public class HomeController : Controller
{
public ActionResult Index()
{
ControllerContext.HttpContext.Response.Cookies.Add(
new HttpCookie("test", "hello") { Path = @"/Admin",
Expires = DateTime.Now.AddDays(1)});
return RedirectToAction("About", "Admin");
}
}
public class AdminController : Controller
{
public ActionResult About()
{
var cookieCount = HttpContext.Request.Cookies.Count;
return View();
}
}
<强>当量强>
# single string, not null so true, and result is yes
test 10==11 && echo yes || echo no
# there exist space 10 == 11 not equal string comparison so result no
test 10 == 11 && echo yes || echo no
来自http://tldp.org/LDP/abs/html/comparison-ops.html
if test 10==11; then echo yes; else echo no; fi
yes
if test 10 == 11; then echo yes; else echo no; fi
no
# or this same as above
if test 10 = 11; then echo yes; else echo no; fi
no