在實(shí)際項(xiàng)目中編寫的幾個(gè)小shell腳本
- gradle build 啟用守護(hù)進(jìn)程,下次編譯速度提高
#!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 請(qǐng)求鏈接
#!/bin/sh
#此腳本是用來(lái)使用curl請(qǐng)求鏈接的
#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
- 腳本編譯安裝啟動(dòng)項(xiàng)目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)
- 網(wǎng)絡(luò)請(qǐng)求 包含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 這里是一個(gè)循環(huán)結(jié)束的標(biāo)志.輸入這個(gè)標(biāo)志表示我需要傳遞的json數(shù)據(jù)已經(jīng)全部寫進(jìn)去了
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