免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1406 | 回复: 2
打印 上一主题 下一主题

[数值计算] if [ $a = "123" ] 与 if [ $a == "123 ] [复制链接]

论坛徽章:
4
丑牛
日期:2014-01-11 15:11:12亥猪
日期:2014-12-15 22:19:092015年辞旧岁徽章
日期:2015-03-03 16:54:152015年亚洲杯之约旦
日期:2015-03-13 19:45:11
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-08-01 21:41 |只看该作者 |倒序浏览
在有些书中说字符串判断相等用=,如if [ $a = "123" ],我在linux上用==,如:if [ $a == "123 ]依然可以正确运行,请问这是bash的新特性吗?
bash 版本4.2

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [报告]
发表于 2016-08-01 21:46 |只看该作者
回复 1# 魔鬼的惊叹

$ man bash
NAME
       bash - GNU Bourne-Again SHell
...
CONDITIONAL EXPRESSIONS
       Conditional expressions are used by the [[  compound  command  and  the
       test  and [ builtin commands to test file attributes and perform string
       and arithmetic comparisons.  Expressions are formed from the  following
       unary  or  binary  primaries.   If any file argument to one of the pri‐
       maries is of the form /dev/fd/n, then file descriptor n is checked.  If
       the  file  argument  to  one  of  the  primaries  is one of /dev/stdin,
       /dev/stdout, or /dev/stderr, file descriptor 0, 1, or 2,  respectively,
       is checked.
...

       string1 == string2
       string1 = string2
              True  if  the strings are equal.  = should be used with the test
              command for POSIX conformance.

       string1 != string2
              True if the strings are not equal.


   

论坛徽章:
4
丑牛
日期:2014-01-11 15:11:12亥猪
日期:2014-12-15 22:19:092015年辞旧岁徽章
日期:2015-03-03 16:54:152015年亚洲杯之约旦
日期:2015-03-13 19:45:11
3 [报告]
发表于 2016-08-02 10:30 |只看该作者
回复 2# jason680
用了linux很长时间,貌似好像还没有好好看过man bash,而且我还发现了一些新的特性,看的书貌似都有些老了
多谢多谢


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP