在实际项目中编写的几个小shell脚本
gradle build 启用守护进程,下次编译速度提高
#!bin/sh./gradlew build --daemon --parallel --offlineecho "enter enyone character"read characteradb install /Users/bjhl/Desktop/XXTT/xxtt-android/xuexitoutiao/build/outputs/apk/xuexitoutiao-zx-debug.apkcurl 请求链接
#!/bin/sh#此脚本是用来使用curl请求链接的#http://dev-app.*****.com/ dev#http://app.****.cn/ 线上echo "enter the request urltopic/list)"read urlecho "enter the request paramspage=*&size=*&channel=**)"read paramscurl -d $params"&sig=****&client={\"appId\":\"****\",\"deviceId\":\"*****\",\"from\":\"**\",\"mac\":\"***\",\"model\":\"androidXT1085\",\"os\":\"android22\",\"version\":\"3\"}" "http://****.com/"$url脚本编译安装启动项目app
#!bin/shecho $(date +%Y-%m-%d:%H:%M:%S)source ~/.bash_profileecho "compiling..."gradle buildecho "uninstall..."adb uninstall com.****.***echo "install..."adb install /Users/bjhl/Desktop/***/**/***/build/outputs/apk/***-debug.apkecho "start MainActivity..."adb shell am start -n "com.****.***/com.***.***.MainActivity.java" -a android.intent.action.MAIN -c android.intent.category.LAUNCHERecho $(date +%Y-%m-%d:%H:%M:%S)网络请求 包含cookie
#!/bin/shecho -n "enter the request host: "read host # request host#cookieecho -n "use cookie ? (y/n) "read is_cookiecookie=""#if need cookie setif [[ $is_cookie = "y" ]]; thenecho -n "input the cookie: "read input_cookiecookie=$input_cookiefiecho -n "need post? (y/n) "read tag#http get if tag = nif [[ $tag = "n" ]]; thenif [[ $cookie != "" ]]; thencurl $host -b$cookieelsecurl $hostfiexit 0fi#the json data need to postdata=""#the input value pairkv_pair=""while true; doif [[ $tag = "y" ]]; then#input keyecho -n "key : "read key# set break condition key = gameover 这里是一个循环结束的标志.输入这个标志表示我需要传递的json数据已经全部写进去了if [[ $key = "gameover" ]]; then#complete the json format, %,* start at right side and romove the first ','kv_pair=${kv_pair%,*}#this is the last data to postdata="{"$kv_pair"}"echo "post data is: $data and exce the curl cmd"#curl $host -d$databreak;fi#encode with ""key='"'$key'"'#input valueecho -n "value : "read value#encode value with ""value='"'$value'"'#set value pair and extends itselfkv_pair="$kv_pair"$key":"$value","echo "$kv_pair"fidone#do http postif [[ $cookie != "" ]]; thencurl $host -d$data -b$cookieelsecurl $host -d$datafi |