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"'
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]