2013年2月24日 星期日

grep -w(--word-regexp)




-w--word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.

2013年2月23日 星期六

bash script 常用變數技巧



   Bash basic concepts

   http://wiki.bash-hackers.org/scripting/basics

  Bash script parameter substitution

   http://tldp.org/LDP/abs/html/parameter-substitution.html



 ${!varprefix*}${!varprefix@}

Matches names of all previously declared variables beginning with varprefix.

# This is a variation on indirect reference, but with a * or @.
# Bash, version 2.04, adds this feature.

xyz23=whatever
xyz24=

a=${!xyz*}         #  Expands to *names* of declared variables
# ^ ^   ^           + beginning with "xyz".
echo "a = $a"      #  a = xyz23 xyz24
a=${!xyz@}         #  Same as above.
echo "a = $a"      #  a = xyz23 xyz24

echo "---"

abc23=something_else
b=${!abc*}
echo "b = $b"      #  b = abc23
c=${!b}            #  Now, the more familiar type of indirect reference.
echo $c            #  something_else








from 鳥哥


Python的private method與protected method



# protected method
   在method名稱前面加上"_"   // protected在方法名稱前面加上"底線(_)"

# private method
   在method名稱之前加上"__" // private在方法名稱前面加上"雙底線(__)"



My understanding of Python convention is

 _member  is protected
 __member  is private


@@ Options for if you control the parent class @@

- Make it protected instead of private since that seems like what you really
want
- Use a  getter(@property def _protected_access_to_member...)  to limit the
protected access


@@ If you don't control it @@

 Undo the name mangling.

If you dir(object) you will see names something like
_Class__member which is what Python does to leading __ to "make it private".
There isn't truly private in python. This is probably considered evil.


http://stackoverflow.com/questions/797771/python-protected-attributes



--------------------------------------------------------------------------
@@ Private Method @@

http://blog.roodo.com/thinkingmore/archives/13763931.html


http://stackoverflow.com/questions/3385317/private-variables-and-methods-in-python
http://blog.roodo.com/thinkingmore/archives/13763931.html

set -x的作用



如果在script中加入了命令"set -x"(xtrace)那麼在set命令之後的每一行命令以及加在命令行中的任何參數(包含"變數""變數的值")都會顯示出來。

每一行之前都會加上(+)提示它是跟蹤輸出的。
在子shell中執行的shell跟蹤命令則會加上"++"。 

from: http://banxi1988.iteye.com/blog/1213914