在实际项目中编写的几个小shell脚本
- gradle build 启用守护进程,下次编译速度提高
#!bin/sh
./gradlew build --daemon --parallel --offline
echo "enter enyone character"
read character
adb install /Users/bjhl/Desktop/XXTT/xxtt-android/xuexitoutiao/build/outputs/apk/xuexitoutiao-zx-debug.apk
- curl 请求链接
#!/bin/sh
#此脚本是用来使用curl请求链接的
#http://dev-app.*****.com/ dev
#http://app.****.cn/ 线上
echo "enter the request url:(topic/list)"
read url
echo "enter the request params:(page=*&size=*&channel=**)"
read params
curl -d $params"&sig=****&client={\"appId\":\"****\",\"deviceId\":\"*****\",\"from\":\"**\",\"mac\":\"***\",\"model\":\"androidXT1085\",\"os\":\"android22\",\"version\":\"3\"}" "http://****.com/"$url
- 脚本编译安装启动项目app
#!bin/sh
echo $(date +%Y-%m-%d:%H:%M:%S)
source ~/.bash_profile
echo "compiling..."
gradle build
echo "uninstall..."
adb uninstall com.****.***
echo "install..."
adb install /Users/bjhl/Desktop/***/**/***/build/outputs/apk/***-debug.apk
echo "start MainActivity..."
adb shell am start -n "com.****.***/com.***.***.MainActivity.java" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo $(date +%Y-%m-%d:%H:%M:%S)
- 网络请求 包含cookie
#!/bin/sh
echo -n "enter the request host: "
read host # request host
#cookie
echo -n "use cookie ? (y/n) "
read is_cookie
cookie=""
#if need cookie set
if [[ $is_cookie = "y" ]]; then
echo -n "input the cookie: "
read input_cookie
cookie=$input_cookie
fi
echo -n "need post? (y/n) "
read tag
#http get if tag = n
if [[ $tag = "n" ]]; then
if [[ $cookie != "" ]]; then
curl $host -b$cookie
else
curl $host
fi
exit 0
fi
#the json data need to post
data=""
#the input value pair
kv_pair=""
while true; do
if [[ $tag = "y" ]]; then
#input key
echo -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 post
data="{"$kv_pair"}"
echo "post data is: $data and exce the curl cmd"
#curl $host -d$data
break;
fi
#encode with ""
key='"'$key'"'
#input value
echo -n "value : "
read value
#encode value with ""
value='"'$value'"'
#set value pair and extends itself
kv_pair="$kv_pair"$key":"$value","
echo "$kv_pair"
fi
done
#do http post
if [[ $cookie != "" ]]; then
curl $host -d$data -b$cookie
else
curl $host -d$data
fi