$0 表示shell文件本身的文件名.
$1,$2,$3 指向每個參數
$#表示參數的個數
$*/$@表示所有參數的整體
$x 用於取變量x的值
$$ 進程id.
shift移動一個參數。
':',相當於nop,是一條空命令,while[ true ] : --> 死循環.
';',用於在一行分隔命令,if[ condition ] ; then
export x=100 ;導出一個環境變量x.
命令替換:使用`A`或者$(A),將$(A)的操作結果,傳給下一個調用者.
eg cat $(ls) > merge // cat `ls` > merge
exit val ;結束當前腳本並以val作爲返回值.
$? ; 返回上一條命令的執行結果.
test 用於shell條件判斷,if test 2 -eq 2//不需要[]
----用於測試文件信息是否正確-----
test -f fn ;fn是否爲爲文件
test -d fn ;fn是否爲文件夾
test -r/w/x ;當前用戶對該文件是否有讀/寫/執行權限
----value--------------
test "sfas" == "afds"
test "sf" -eq "afas"
test 12 -lt 13
&& 和 || 就是那個意思沒錯!!!!!
標準shell變量(內置)
date--> 日期
pwd --> 當前絕對工作路徑
賦值與循環分支
let i=$x+$y,爲整數操作賦值,所以必須有兩個以上操作數.當只有一個操作數時使用,i=$x.
#!/bin/bashecho"please input num:"read num
echo"the num is $num"#聲明變量,不能有空格
sum=0
i=0# while循環,需要留出空格while [ $num-gt$i ]
dolet mo=$i%2# 開始條件需要留出空格# then,else 要單獨留出空行if [ $mo-eq0 ]
then3 賦值不能有空格
let sum=$sum+$ielif [ $mo-eq2 ]
thenecho"ll"else
touch $i
tar cvf - `find . -mtime -1 -type f -print` > x.tar
# 結束條件filet i=$i+1# 結束循環doneecho"the sum is $sum"
for循環以及數組
#!bin/bashecho"my student number is :1133710513, my name is zhiwei huang"
city[1]=Beijing
city[2]=Shanghai
city[3]=Wuxi
city[4]=Wenzhou
city[5]=Berkeley
# for z in 1 2 7for i in${city[*]}doecho$idone
打印
#!/bin/bashecho"my student number is :1133710513, my name is zhiwei huang"
i=0for ((k=0;k<10;k++))
dofor((j=0;j<=k;j++))
doecho -n "$j "doneecho" "done