简体   繁体   English

无法在 bash 脚本中运行 adb 命令

[英]Can't run adb commands in bash script

I'm trying to launch Android tethering settings from adb shell.我正在尝试从 adb shell 启动 Android 网络共享设置。 The main purpose of doing so is to enable USB tethering mode by running a shell script.这样做的主要目的是通过运行 shell 脚本来启用 USB 网络共享模式。 I'm using the following set of commands on my Ubuntu Terminal (12.04):我在我的 Ubuntu 终端 (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.当命令一个一个执行时,此方法工作正常,但我无法将它们作为正常的 shell 脚本运行。 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.我猜,它在我的系统中找不到 adb 的路径。 I've tried replacing the first line with the actual path to adb tool in SDK directory.我尝试用 SDK 目录中 adb 工具的实际路径替换第一行。 That didn't work either.那也没有用。 Any work around for this?有什么解决办法吗? (Sorry if the question seems silly. I'm really new to bash scripting!) (对不起,如果这个问题看起来很愚蠢。我真的是 bash 脚本的新手!)

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
"

adb shell opens a shell on your Android device. adb shell在您的 Android 设备上打开一个 shell。 The subsequent commands are entered in the context of that shell.后续命令在该 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
"

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 start-server
    ./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.唯一的问题是在 adb 之前缺少“./”。

EDIT: also why not check to see if the server is running first?编辑:为什么不先检查服务器是否正在运行?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM