Can't run adb commands in bash script

被刻印的时光 ゝ 提交于 2020-01-11 07:11:09

问题


I'm trying to launch Android tethering settings from adb shell. The main purpose of doing so is to enable USB tethering mode by running a shell script. I'm using the following set of commands on my Ubuntu Terminal (12.04):

adb shell
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607

This method works fine when the commands are executed one by one, but I'm not able to run them as normal shell script. Please help! Here is the complete script:

#!/bin/sh
adb shell
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607

I guess, it can't find the path to adb in my system. I've tried replacing the first line with the actual path to adb tool in SDK directory. That didn't work either. Any work around for this? (Sorry if the question seems silly. I'm really new to bash scripting!)

EDIT: Updated script:-

#!/bin/sh
cd /home/evinish/Documents/Android/adt-bundle-linux-x86_64-20130219/sdk/platform-tools
adb shell "
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607
"

回答1:


adb shell opens a shell on your Android device. The subsequent commands are entered in the context of that shell. Add quotes around the remote commands:

adb shell "
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607
"



回答2:


Thanks everybody! I finally solved the problem. Here is the updated script:

#!/bin/sh
cd /home/evinish/Documents/Android/adt-bundle-linux-x86_64-20130219/sdk/platform-tools
./adb devices
./adb shell "
am start -n com.android.settings/.TetherSettings
sleep 15
input tap 162 159
input tap 385 607
"
sleep 10

The only problem was missing "./" before adb.



来源:https://stackoverflow.com/questions/20765134/cant-run-adb-commands-in-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!