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

帮忙写个超简单脚本
本人小小小白,没碰过shell,希望高手能帮我个举手之劳。
脚本要实现这样的功能,首先检测“/mnt/1/1.txt”里面的内容是否为1,如果内容为1,则把/system/etc/2.txt修改成3.txt。如果内容为2则把/system/etc/3.txt改成2.txt。如果内容既不是1也不是2,则什么都不执行。
脚本 shell 简单

------解决方案--------------------
#!/bin/sh
if [ -f /mnt/1/1.txt ];then
    var=$(cat /mnt/1/1.txt)
else
    exit 1
fi
if [ x"$var" = x"1" ];then
    if [ -f /system/etc/2.txt ];then
        mv /system/etc/2.txt /system/etc/3.txt
    else
        echo "error /system/etc/2.txt not exist"
    fi
elif [ x"$var" = x"2" ];then
    if [ -f /system/etc/3.txt ];then
        mv /system/etc/3.txt /system/etc/2.txt
    else
        echo "error /system/etc/3.txt not exist"
    fi
else
    : echo "noting to do"
fi