7

I'm trying to find a single line solution for entering a shell using ADB on an android device and going straight into a different directory.

Trying something like this

./adb shell cd /insert_dir_here

does not work.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Rstew
  • 585
  • 2
  • 9
  • 21
  • 1
    I understand your query, However once the command is executed, the control is returned back to the `host shell`. Example : `adb shell "cd /tmp && ls"` - Will `cd` into `tmp`, `list` contents of `tmp`, finally returning control to the Host. Its doing what its suppose to do, however I doubt that the control can be retained. Hopefully some way to do it *Fingers crossed* :) – Saurabh Meshram Dec 09 '14 at 04:55
  • Also it would help to know your *actual objective* after this step, Are you trying to run some application or some script after `cd` into the `dir` ? – Saurabh Meshram Dec 09 '14 at 04:57
  • I'm basically iterating through directories of the connected device. I'm currently using Applescript to make a little file transfer app, later on today I will be making a cocoa xcode project for it. The main thing I need to be able to do is, iterate through directories of the device, any suggestions are welcome :) – Rstew Dec 09 '14 at 18:48

2 Answers2

1

Following adb shell with a command, executes it remotely and returns to the hosts shell right after that. so ./adb shell cd /insert_dir_here does work, but the shell exits right away.

what kind of commands do you want to execute after changing the directory?

I suggest using the command alias followed with your series of commands:

alias myADB="cd /to/path; command1 args; command2 args; etc...."

then execute your alias in your own shell "not the adb shell"

myADB
Al Kafri Firas
  • 323
  • 3
  • 15
  • I guess so! I have found threads already giving this solution, I was hoping for something simpler. Anyways thanks for the answer! +1 for you – Rstew Dec 09 '14 at 18:49
1

expect solution

adb-cmd:

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

Then:

adb-cmd cd /data/

Likely this can be improved by someone who knows more Tcl than me.

Superset: adb shell run command and remain in shell

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985