2.SHELL编程

1.一些SHELL命令:
    $ls -l > lsoput.txt #覆盖
    $ps >> lsoput.txt  #附加
    $kill -HUP 1234 >killouterr.txt 2>&1
    $ps -xo comm | sort | uniq | grep -v sh | more 

2  $ss=hello       $ss="hello"          $ss=7+5          
   $echo $ss     
$echo $ss           $echo $ss
   result: hello     result: hello         result:7+5
 
   $read ss         $echo $ss
   wie get          $echo "$ss"
   $echo $ss        $echo '$ss'
   wie get          $echo /$ss

3. 环境变量
  $HOME $PATH $PS1 $PS2 $IFS $0 $# $$
  参数变量
  $0 $1 $2 .... $* $@

4. 条件测试,可进行字符串比较,算术比较,文件测试
   test 或 [ ]

5. if condition         
if condition
   then                then
     statements             statements
   else                 elif condition; then
     statements            
statements
   fi                   else
                          
statements
                      fi

6. for file in $(ls f*.sh)
   do
     lpr $file
   done

7. #!/bin/sh
  foo=1
  while [ "$foo" le 20 ]
  do
    fo=$($(foo+1))
  done

8.until condtion
  do
    statements
  done

9.#i/bin/sh

  read timeofday
  case "$timeofday" in
     yes | y | Yes |YES )
        echo "Good"
        echo "darly"
        ;;
     [nN]*)
        echo "good"
        ;;
     *)
        exit 1
        ;;
  esac

10. && || {}

11.SHELL程序中,当一个函数被调用,脚本程序大位置参数$* $# $1等会被替换为函数大参数,函数执行完后,这些参数会恢复原直,让函数返回变量的作法通常是在函数中对变量复直,然后在main函数中调用该变量,可以用local声明局部变量。
#!/bin/sh

yes_or_no()
{
    echo "your name is $* $0 $1 $2 $3"
    while :
    do
        echo -n "Enter yes or no: "
        read x
        case "$x" in
            [yY]*) return 0;;
            [nN]*) return 1;;
            *)        echo "Enter yes or no"
        esac
    done
}

12

echo "parameters are $@"

if yes_or_no "haha dede yeye"
#if :
then
    echo "Hi $1"
else
    echo "Never mind"
fi

exit 0

12.break : continue . eval $(()) exec eixt n export expr printf return set shift trap unset

13 find grep

14.算术扩展$((..))与执行命令$(..)的区别,参数扩展${param},here文档<<

15.脚本调试  sh -n -x -v
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值