本文共 3311 字,大约阅读时间需要 11 分钟。
(1)它必须以如下行开始(必须放在文件的第一行):
# !/bin/sh 符号#!用来告诉系统执行该脚本的程序,本例使用/bin/sh。编辑结束并保存后,如果要执行该脚本,必须先使其可执行: chmod +x filename 此后在该脚本所在目录下,输入 ./filename 即可执行该脚本。 (2)变量赋值和引用。Shell编程中,使用变量无需事先声明,需要给变量赋值时,可以这么写: 变量名=值 。 要取用一个变量的值,只需在变量名前面加一个$ ( 注意: 给变量赋值的时候,不能在"="两边留空格 ) # 对字符串变量赋值: a="hello world" # 打印字符串变量a的值: echo "A is:" $a 执行结果:A is: hello world如果是变量不用输出到终端,直接在sh文件内部调用,使用单括号即可:
PRODUCT='real6410'
调用到的地方使用:
mkdir -p out/target/product/$PRODUCT/obj/lib
(3)if 语句。"if"表达式如果条件为真,则执行then后的部分: if ....; then .... elif ....; then .... else .... fi 通常用" [ ] "来表示条件测试,注意这里的空格很重要,要确保方括号前后的空格。例如: [ -f "somefile" ] :判断是否是一个文件 [ -x "/bin/ls" ] :判断/bin/ls是否存在并有可执行权限 [ -n "$var" ] :判断$var变量是否有值 [ "$a" = "$b" ] :判断$a和$b是否相等(4)循环。
while ...; do .... done 只要测试表达式条件为真,则while循环将一直运行。关键字"break"用来跳出循环,而关键字”continue”则可以跳过一个循环的余下部分,直接跳到下一次循环中。(5)函数功能
在sh中可以定义某段类似于函数的集成语句段,在名字前使用function申明。方法如:
function real6410_prebuild()
{ mkdir -p out/target/product/$PRODUCT/obj/lib mkdir -p out/target/product/$PRODUCT/system/lib cp vendor/realarm/real6410/*.so out/target/product/$PRODUCT/obj/lib cp vendor/realarm/real6410/*.so out/target/product/$PRODUCT/system/lib }之后,在其他地方直接使用real6410_prebuild就行了。
(6)sync
(7)实例,可执行脚本update的内容如下。
#!/bin/bashif [ "$1" = "" ]; then echo "Please input resolution," echo "Such as: qvga, wqvga, wvga, hvga" exitfip=$1./tool/bmp_to_raw ./temp0.raw ./$p/"${p}_uboot".bmp./tool/bmp_to_raw ./temp1.raw ./$p/"${p}_battery00".bmp./tool/bmp_to_raw ./temp2.raw ./$p/"${p}_battery02".bmp./tool/bmp_to_raw ./temp3.raw ./$p/"${p}_battery04".bmp./tool/bmp_to_raw ./temp4.raw ./$p/"${p}_battery06".bmp./tool/bmp_to_raw ./temp5.raw ./$p/"${p}_battery08".bmp./tool/bmp_to_raw ./temp6.raw ./$p/"${p}_low_battery1".bmp./tool/bmp_to_raw ./temp7.raw ./$p/"${p}_low_battery2".bmp./tool/bmp_to_raw ./temp8.raw ./$p/"${p}_batteryfull".bmp./tool/bmp_to_raw ./temp9.raw ./$p/"${p}_charger_ov".bmp./tool/bmp_to_raw ./boot_logo ./$p/"${p}_kernel".bmp./tool/zpipe -l 9 ./"${p}.raw" temp0.raw temp1.raw temp2.raw temp3.raw temp4.raw temp5.raw temp6.raw temp7.raw temp8.raw temp9.rawrm -rf ./temp0.raw ./temp1.raw ./temp2.raw ./temp3.raw ./temp4.raw ./temp5.raw ./temp6.raw ./temp7.raw ./temp8.raw ./temp9.raw ./bootlogo.rawecho "conversion finished"
说明:$1表示第一个参数;以上命令依次执行。
转载地址:http://zbbsi.baihongyu.com/