欢迎大家把linux shell编程中遇到的符号做个汇总 谢谢

s970741
欢迎大家把linux shell编程中遇到的符号做个汇总 谢谢

在shell编程中常常会遇到一些变态的符号,google查找有的也不方便,欢迎大家把linux  shell编程中遇到的符号做个汇总重复的就不要发了 谢谢  小弟抛砖引玉
例如:匹配操作符~ 相当余==
例子:awk '$1 ~/xxx/' urfile相当于 awk '$1 == "xxx"'  urfile      
解释: 将显示第1个域中 与xxx相匹配的行

ly5066113
[quote]原帖由 [i]s970741[/i] 于 2008-6-30 11:01 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8701170&ptid=1184424][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]
在shell编程中常常会遇到一些变态的符号,google查找有的也不方便,欢迎大家把linux  shell编程中遇到的符号做个汇总重复的就不要发了 谢谢  小弟抛砖引玉
例如:匹配操作符~ 相当余==
例子:awk '$1 ~/xxx/' ... [/quote]

~ 和 == 不等价。

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

无声无息
匹配和等同是不同的

s970741
例子不严谨 谢谢楼上的指正了  也是给我们这些初学者做个反面教材
还有没有类似的例子老师们尽管跟帖啊  方便大家学习 谢谢

blackold
范围也太大了,这些符号太多了。

s970741
^匹配行首的字符 ls -l|grep ^d
$匹配行尾的字符  
^$这是空行
.匹配一个字符
/去掉元字符特殊含义  匹配*.bat结尾的  /*/.bat$

无声无息
把正则中列一边就好了

walkerxk
还是去看看精通正则表达式吧,不然说不清楚的。

hosuk1208
~ 是说用正则
和==不一样

r2007
abs第三章,篇幅有点长,贴了一小段,最好自己看[code]Chapter 3. Special Characters
What makes a character special? If it has a meaning beyond its literal meaning, a meta-meaning, then we refer
to it as a special character.
Special Characters Found In Scripts and Elsewhere
#
Comments. Lines beginning with a # (with the exception of #!) are comments and will not be
executed.
# This line is a comment.
Comments may also occur following the end of a command.
echo "A comment will follow." # Comment here.
# ^ Note whitespace before #
Comments may also follow whitespace at the beginning of a line.
# A tab precedes this comment.
A command may not follow a comment on the same line. There is no method of
terminating the comment, in order for "live code" to begin on the same line. Use a new
line for the next command.
Of course, an escaped # in an echo statement does not begin a comment. Likewise, a #
appears in certain parameter substitution constructs and in numerical constant
expressions.
echo "The # here does not begin a comment."
echo 'The # here does not begin a comment.'
echo The /# here does not begin a comment.
echo The # here begins a comment.
echo ${PATH#*:} # Parameter substitution, not a comment.
echo $(( 2#101011 )) # Base conversion, not a comment.
# Thanks, S.C.
The standard quoting and escape characters (" ' /) escape the #.
Certain pattern matching operations also use the #.
;
Command separator [semicolon]. Permits putting two or more commands on the same line.
echo hello; echo there
if [ -x "$filename" ]; then # Note that "if" and "then" need separation.
# Why?
echo "File $filename exists."; cp $filename $filename.bak
else
echo "File $filename not found."; touch $filename
fi; echo "File test complete."[/code]

Shell_HAT
$#
获取参数的个数(0表示沒有参数)

$*
获取全部参数

$@
获取全部参数

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

$$
获取当前shell的PID