shell 编程笔记

来源:互联网 发布:德国拜发测毒素软件 编辑:程序博客网 时间:2024/06/07 19:04
1 #!/bin/sh
#!告诉系统它后面的参数是用来执行该文件的程序

2 chmod +x filename 
权限

3 ./filename   
执行

4 变量
不需要对变量进行声明,要赋值给一个变量,取变量加$在变量前
如: a=test     echo $a

5 shell脚本中使用三类命令:
(1)脚本里面可以使用任意unix命令,常用命令:
echo    ls    wc   cp  mv    rm   grep   cut   cat   file  read   sort  uniq   expr
find  tee  basename   doorman    head  tail   sed    awk

(2)概念:
管道(|):将一个命令的输出作为另一个命令的输入
重定向 : >  输入到文件,覆盖      >> 追加,不覆盖
反短斜线(-):可以将一个命令的输出最为另一个命令的一个命令行参数

(3)流程控制:
if [ “” = “/bin/bash  ]; then
     echo “this is bash
else
     echo “this is not bash"
fi

select var in  ; do
     break
done

while-loop
for-loop

6   $1 脚本后面的第一个参数
     $* 所有命令行参数,一个数组
     $#  表示参数的个数

7 单引号可以放置任何变量扩转,双引号之防止通配符扩展
如   *.jpg     *.jpg'

8 shift  删除参数

9 长字符串   
<<xxx      
………………...
xxx



















0 0
原创粉丝点击