How to run an adb shell command and remain in the shell?

前端 未结 3 851
攒了一身酷
攒了一身酷 2021-01-11 12:48

Does anyone know how to run commands from adb shell and remain in shell session? What I`m trying to achieve is to set aliases in adb shell.

I have tried the followi

相关标签:
3条回答
  • 2021-01-11 13:18

    There was a similar question answered in the comments here.

    In short, run the following from your terminal:

    stty raw -echo ; ( echo "ls" && cat ) | adb shell ; stty sane

    Note: without the stty magic, the command is piped to adb and tab complete etc. is not recognized.

    0 讨论(0)
  • 2021-01-11 13:25

    expect solution

    adb-cmd:

    #!/usr/bin/env expect
    spawn adb shell
    expect "#"
    send [ concat [ join $argv " " ] ]
    send "\r"
    interact
    

    Usage:

    adb-cmd 'cd /data/data; ls'
    

    Tested in Ubuntu 16.04 host, Android O guest.

    0 讨论(0)
  • 2021-01-11 13:26

    When you run:

    adb shell ls
    

    You are running this command currently outside of ADB.

    First, you need to enter ADB:

    adb shell
    

    Once you enter ADB shell, you can continue to see output and input more commands.

    ls
    help
    

    To exit ADB, simply type "exit" or hit "Ctrl + C"

    0 讨论(0)
提交回复
热议问题