Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用脚本编辑android build.prop_Android_Shell_Scripting - Fatal编程技术网

使用脚本编辑android build.prop

使用脚本编辑android build.prop,android,shell,scripting,Android,Shell,Scripting,我正在尝试创建一个脚本来“自动”修改build.prop文件。 我希望脚本检查我定义的条目,并: 1如果它们不存在,请添加它们 2如果它们确实存在,请检查该值,如果它与我定义的不匹配,请修改它 我已经创建了一个脚本。 它运行但不输出任何内容,不更改build.prop 我已经附上了剧本。对吗 #!/system/bin/sh # Definitions file=/system/build.prop tmpf=/system.buildprop.bak line_list="wifi.s

我正在尝试创建一个脚本来“自动”修改build.prop文件。 我希望脚本检查我定义的条目,并: 1如果它们不存在,请添加它们 2如果它们确实存在,请检查该值,如果它与我定义的不匹配,请修改它

我已经创建了一个脚本。 它运行但不输出任何内容,不更改build.prop

我已经附上了剧本。对吗

#!/system/bin/sh 

# Definitions 
file=/system/build.prop 
tmpf=/system.buildprop.bak
line_list="wifi.supplicant_scan_interval=120 ro.sf.lcd_density=480" 

# Function to get args as needed for loop
getargs() {

par=$1
line=`echo $par |cut -d"=" -f1`
arg=`echo $par |cut -d"=" -f2`
} 

# Loop to make all changes in line_list 
for x in $line_lst; do 

# Get all needed arguments 
getargs $x 

# Write this change to a tmp file to check on it
oldarg=`grep $line $file |cut -d"=" -f2`
sed "s/$line=.*/$line=${arg}/g" $file > $tmpf

# Check if the change was made
chknewarg=`grep $line $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
cp $tmpf $file
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "File edited"
else
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
# If it doesn't exist at all append it to the file
chkexists=`grep -c $line $file`
if [ $chkexists -eq 0 ]; then
echo "$x" >> $file
fi
done
exit 0

我做了更多的游戏,从根本上改变了剧本

#/system/bin/sh

 mount -o remount,rw /system

FILE=/system/build.prop
TMPFILE=$FILE.tmp

line1=wifi.supplicant_scan_interval
line2=ro.sf.lcd_density
line3=ro.media.enc.jpeg.quality

line1Arg=120
line2Arg=390
line3Arg=100

lineNum=

prop=$line1     
arg=$line1Arg   
if grep -Fq $prop $FILE ; then  
lineNum=`sed -n "/${prop}/=" $FILE`   
echo $lineNum
sed -i "${lineNum} c${prop}=${arg}" $FILE   
else
echo "$prop does not exist in build.prop"   
echo "appending to end of build.prop"
echo $prop=$arg >> $FILE
fi

prop=$line2     
arg=$line2Arg     
if grep -Fq $prop $FILE ; then  
lineNum=`sed -n "/${prop}/=" $FILE`    
echo $lineNum
sed -i "${lineNum} c${prop}=${arg}" $FILE    
else
echo "$prop does not exist in build.prop"   
echo "appending to end of build.prop"
echo $prop=$arg >> $FILE
fi

prop=$line3     
arg=$line3Arg     
if grep -Fq $prop $FILE ; then  
lineNum=`sed -n "/${prop}/=" $FILE`    
echo $lineNum
sed -i "${lineNum} c${prop}=${arg}" $FILE    
else
echo "$prop does not exist in build.prop"   
echo "appending to end of build.prop"
echo $prop=$arg >> $FILE
fi

mount -o remount,r /system
但是我得到一个“mount:invalid argument”错误


此外,如何在行和线性arg变量上循环以竞争操作?

使用
sh-x
运行脚本以更轻松地调试它。另外,稍微缩进代码不会有什么坏处,它肯定会使代码更可读。
的mount:invalid参数是因为只读重新装载应该是
mount-o remount,ro/system