2011
Nov
21
基礎
- wc -l :計算行數
Example
- [user]conf$ cat php.ini | wc -l
- 1299
- 比較數字大小 -lt , -gt
Example
- a=1
- b=2
- c=3
- if [ "$a" -lt "$b" ]; then
- echo "$a is smaller then $b";
- fi
- if [ "$c" -gt "$b" ]; then
- echo "$c is bigger then $b";
- fi
- for 迴圈
Example
- for i in 1 2 3 4 5 6 7 8 9 10
- do
- echo -n "...$i"
- done
- 字串擷取,試著擷取第2到第5的文字
Example
- data="a apple a day keeps the doctor away"
- echo "${data:2:5}"
- echo "${data:10:3}"
- 印出所有的檔案
Example
- r_file(){
- dir=$1
- files=$dir/*
- for filename in $files
- do
- if [ -d $filename ]; then
- echo $filename
- r_file "$filename"
- elif [ -f $filename ]; then
- echo $filename
- else
- #echo "not file" $filename
- echo ""
- fi
- done
- }
- r_file /home/
tr
tr (translate): 字母轉換
用 16 進位的方式存檔
hex
- echo -e '\x61\x62' > tmp
回應 (Leave a comment)