How to run adb shell command and stay in shell?

Does anyone know how to run commands from an adb shell and stay in a shell session? What I'm trying to achieve is to set aliases in the adb shell.

I tried the following without success

adb shell <<< "ls" 

After executing this command, it really remains in the shell, but cannot receive the output of any additional command.

I also tried the following:

 adb shell <<EOF ls EOF 

with the same result.

+9
source share
3 answers

When you run:

 adb shell ls 

You are currently executing this command outside of ADB.

First you need to enter ADB:

 adb shell 

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

 ls help 

To exit ADB, simply enter "exit" or press "Ctrl + C"

+14
source

expect solutions

adb-cmd :

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

Using:

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

Tested on host Ubuntu 16.04, Android O guest.

+3
source

The comments here had a similar question.

In short, run the following on your terminal:

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

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

+2
source

Source: https://habr.com/ru/post/1397657/


All Articles