Chinaunix

标题: 欢迎大家把linux shell编程中遇到的符号做个汇总 谢谢 [打印本页]

作者: s970741    时间: 2008-06-30 11:01
标题: 欢迎大家把linux shell编程中遇到的符号做个汇总 谢谢
在shell编程中常常会遇到一些变态的符号,google查找有的也不方便,欢迎大家把linux  shell编程中遇到的符号做个汇总重复的就不要发了 谢谢  小弟抛砖引玉
例如:匹配操作符~ 相当余==
例子:awk '$1 ~/xxx/' urfile相当于 awk '$1 == "xxx"'  urfile      
解释: 将显示第1个域中 与xxx相匹配的行
作者: ly5066113    时间: 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"'
作者: 无声无息    时间: 2008-06-30 11:11
匹配和等同是不同的
作者: s970741    时间: 2008-06-30 11:41
例子不严谨 谢谢楼上的指正了  也是给我们这些初学者做个反面教材
还有没有类似的例子老师们尽管跟帖啊  方便大家学习 谢谢
作者: blackold    时间: 2008-06-30 11:44
范围也太大了,这些符号太多了。
作者: s970741    时间: 2008-06-30 12:07
^匹配行首的字符 ls -l|grep ^d
$匹配行尾的字符  
^$这是空行
.匹配一个字符
\去掉元字符特殊含义  匹配*.bat结尾的  \*\.bat$
作者: 无声无息    时间: 2008-06-30 12:20
把正则中列一边就好了
作者: walkerxk    时间: 2008-06-30 14:33
还是去看看精通正则表达式吧,不然说不清楚的。
作者: hosuk1208    时间: 2008-07-01 13:20
~ 是说用正则
和==不一样
作者: r2007    时间: 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."
复制代码

作者: Shell_HAT    时间: 2008-07-01 15:44
$#
获取参数的个数(0表示沒有参数)

$*
获取全部参数

$@
获取全部参数

$?
获取上一条命令的返回值

$$
获取当前shell的PID




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2