bash script 常用技能备忘

赋值

   x="abc"   # = 前后不能有空格

条件判断

   if cond; then
       # some code
   elif cond2; then
       # some code
   fi

   if [ "$a" == "x" ]; then        # 空格不能少
   if oscommand ; then           # oscommand 成功,返回0, oscommand 也返回true, 否则返回false
   example:
   if echo "abc" | grep -q ab; then

function

   function f() {
       echo "f" $1  # $1 为第一个参数
   }

   f "par1"  # 调用函数f,  注意没有括号

   function g() {
       eval "$1='abcdef '"
   }

outstr=''
g outstr
echo $outstr  # $outstr == "abcdef" now
posted @ 2014-12-18 21:21  zhifan  阅读(229)  评论(0)    收藏  举报