免费注册 查看新帖 |

Chinaunix

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

欢迎大家把linux shell编程中遇到的符号做个汇总 谢谢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-30 11:01 |只看该作者 |倒序浏览
在shell编程中常常会遇到一些变态的符号,google查找有的也不方便,欢迎大家把linux  shell编程中遇到的符号做个汇总重复的就不要发了 谢谢  小弟抛砖引玉
例如:匹配操作符~ 相当余==
例子:awk '$1 ~/xxx/' urfile相当于 awk '$1 == "xxx"'  urfile      
解释: 将显示第1个域中 与xxx相匹配的行

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
2 [报告]
发表于 2008-06-30 11:07 |只看该作者
原帖由 s970741 于 2008-6-30 11:01 发表
在shell编程中常常会遇到一些变态的符号,google查找有的也不方便,欢迎大家把linux  shell编程中遇到的符号做个汇总重复的就不要发了 谢谢  小弟抛砖引玉
例如:匹配操作符~ 相当余==
例子:awk '$1 ~/xxx/' ...


~ 和 == 不等价。

echo "123" | awk '$1 ~ /1/'
echo "123" | awk '$1 == "1"'

论坛徽章:
0
3 [报告]
发表于 2008-06-30 11:11 |只看该作者
匹配和等同是不同的

论坛徽章:
0
4 [报告]
发表于 2008-06-30 11:41 |只看该作者
例子不严谨 谢谢楼上的指正了  也是给我们这些初学者做个反面教材
还有没有类似的例子老师们尽管跟帖啊  方便大家学习 谢谢

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
5 [报告]
发表于 2008-06-30 11:44 |只看该作者
范围也太大了,这些符号太多了。

论坛徽章:
0
6 [报告]
发表于 2008-06-30 12:07 |只看该作者
^匹配行首的字符 ls -l|grep ^d
$匹配行尾的字符  
^$这是空行
.匹配一个字符
\去掉元字符特殊含义  匹配*.bat结尾的  \*\.bat$

论坛徽章:
0
7 [报告]
发表于 2008-06-30 12:20 |只看该作者
把正则中列一边就好了

论坛徽章:
0
8 [报告]
发表于 2008-06-30 14:33 |只看该作者
还是去看看精通正则表达式吧,不然说不清楚的。

论坛徽章:
0
9 [报告]
发表于 2008-07-01 13:20 |只看该作者
~ 是说用正则
和==不一样

论坛徽章:
7
荣誉版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07狮子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10双子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
10 [报告]
发表于 2008-07-01 14:01 |只看该作者
abs第三章,篇幅有点长,贴了一小段,最好自己看
  1. Chapter 3. Special Characters
  2. What makes a character special? If it has a meaning beyond its literal meaning, a meta-meaning, then we refer
  3. to it as a special character.
  4. Special Characters Found In Scripts and Elsewhere
  5. #
  6. Comments. Lines beginning with a # (with the exception of #!) are comments and will not be
  7. executed.
  8. # This line is a comment.
  9. Comments may also occur following the end of a command.
  10. echo "A comment will follow." # Comment here.
  11. # ^ Note whitespace before #
  12. Comments may also follow whitespace at the beginning of a line.
  13. # A tab precedes this comment.
  14. A command may not follow a comment on the same line. There is no method of
  15. terminating the comment, in order for "live code" to begin on the same line. Use a new
  16. line for the next command.
  17. Of course, an escaped # in an echo statement does not begin a comment. Likewise, a #
  18. appears in certain parameter substitution constructs and in numerical constant
  19. expressions.
  20. echo "The # here does not begin a comment."
  21. echo 'The # here does not begin a comment.'
  22. echo The \# here does not begin a comment.
  23. echo The # here begins a comment.
  24. echo ${PATH#*:} # Parameter substitution, not a comment.
  25. echo $(( 2#101011 )) # Base conversion, not a comment.
  26. # Thanks, S.C.
  27. The standard quoting and escape characters (" ' \) escape the #.
  28. Certain pattern matching operations also use the #.
  29. ;
  30. Command separator [semicolon]. Permits putting two or more commands on the same line.
  31. echo hello; echo there
  32. if [ -x "$filename" ]; then # Note that "if" and "then" need separation.
  33. # Why?
  34. echo "File $filename exists."; cp $filename $filename.bak
  35. else
  36. echo "File $filename not found."; touch $filename
  37. fi; echo "File test complete."
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP