日期:2014-05-16  浏览次数:21297 次

新人学了两天的shell求帮助
#!/bin/bash
#查询sdcard空间,结果放进文件
adb shell df > diskspace.tmp
#返回行数
length=`awk 'END{print NR}'   diskspace.tmp`
#可用空间 
free=`awk 'NR==15{print $4 }' diskspace.tmp`
free="12M"
echo "$free" | grep -q "G"  
if [ $? -eq 0 ]; then  
    #以G结尾
    freeSize=$((${free%G*}*1024*1024))
else
    echo "$free" | grep -q "M"
    if [ $? -eq 0 ]; then  
        #以M结尾
        freeSize=$((${free%M*}*1024))
    else
        freeSize=$free
    fi
fi
#echo "freeSize:"$freeSize >> android.log

#可用空间小于20M
if(($freeSize <= 20*1024));then
    echo "存储空间不足" >> android.log
    #查询Camera目录下的文件,结果放进文件
    adb shell ls /sdcard/DCIM/Camera > android.tmp
    #返回行数
    length=`awk 'END{print NR}'   android.tmp`
    i=1
    #循环遍历
    while((i <= $length))
    do
        #读取一行
        #awk在行数为参数时无法读取
        line=`sed -n "$i"p ./android.tmp`
        echo "$line" | grep -q ".3gp"
        if [ $? -eq 0 ]; then
            #以3gp结尾
            #此处应删除以3gp结尾的文件
            #直接执行 adb shell rm /sdcard/DCIM/Camera/$line 失败
            #
            line=/sdcard/DCIM/Camera/$line
            echo $line > rm.tmp
            adb shell rm `awk 'NR==1{print}' rm.tmp` >> android.log
            #echo "rm $line" >> android.log

        fi
        i=$(($i+1));
    done
fi

红色处需要执行 adb shell rm filepath 可是死活都执行不了。

------解决方案--------------------
bash -vx test.sh
结果贴出来看看

另外,以3gp结尾的文件应该是这样:
echo "$line" 
------解决方案--------------------
 grep -q "\.3gp$"

------解决方案--------------------
引用:
这个也试过,不可以。。。

我知道不可以。
我的意思是让你按照那种方法执行,把过程贴出来。