Linux shell编程

来源:互联网 发布:网络知识视频教程 编辑:程序博客网 时间:2024/04/27 19:41

#!/bin/bash


#function(int a,intb)
#judge operation
function1()
{
   #a > b?
   if [ $1 -gt $2 ]; then
     echo "hehe"
     return 0
   else
     echo "oo"
     return 1
   fi    
}


function2()
{
  case $1 in
  0)
    echo "the value is 0"
    ;;
  1)
    echo "the value is 1"
    ;;
  2)
    echo "the value is 2"  
    ;;
  esac


  return 0
}


#a & b
function4()
{
  a=0x1e
  b=0x06
  c=$[$a & $b]


  echo $c
  return 0
}

function3()
{
  gg="luoguoxian is a good man /dfs df:abc:0x21"
  want_value=`echo ${gg} | awk -F ":" '{print $3}'`
  echo "in function3 get value: ${want_value}"
  return 0
}

#main
#variable
aa="luoguoxian"
bb=12
cc=23
dd='c'
ff=1

function1 ${bb} ${cc}
echo $?

function2 ${ff}
if [ $? == 0 ]; then
  echo "process function2 successfully"
fi

function3

function4



#一个学习的网址:http://www.runoob.com/linux/linux-shell-func.html