Bash Shell使用技巧

1. Makefile與Shell取環境變量的不同方法

Makefile: cc=$(CROSS_COMPILE)

Shell: cc=$CROSS_COMPILE

 

2.從命令中得到值

removable=$(cat /sys/block/$1/removable)

 

3. while

export TSLIB_TSDEVICE=/dev/ts
counter=1
while [ 1 ] --> 無限循環

while [ $counter -lt 10 ]
do
        aplay music.wav &
        ts_test &
        counter_inner=1
        while [ $counter_inner -lt 60 ]
        do
                sleep 4
                counter_inner=$(( $counter_inner + 1 ))
        done
        pkill ts_test
        counter=$(( $counter + 1 ))
        echo "the counter is $counter"
done

 

4. For

for file in $( find . -type f -name "*.bz2" | sort )
do
        tar xvfj $file -C /scratch/paul/lite/linux/src/
done

 

5. 如何過濾bash的錯誤輸出?

arm-none-linux-gnueabi-gcc -v 2>/dev/null

 

stdin 0<

stdout 1>

stderr 2>

發佈了50 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章