6

I wanted to update the PATH environment variable permanently in the adb shell. I guessed the shell was mksh for I've found /system/bin/sh pointing to /system/bin/mksh. Then I tried

  • Making a new file /data/.mkshrc and adding the PATH definition into it.
  • Copy the above file into /.
  • Copy to /root.

But all attempts failed.

3 Answers 3

9

In addition to what Alex-p wrote, you can also set the ENV environment variable to override the path of the mkshrc file used.

All login shells also read /system/etc/profile and $HOME/.profile (these are a good place to export ENV). Apparently (for some reason that defies my ability to explain), adb shell does not start a login shell¹, though, so /system/etc/mkshrc is the file you will have to change for that.

(Disclaimer: I’m the mksh maintainer.)

① I’d expect “adb shell” to behave like ssh and start login shells if there is no explicit command given, as it does start a (new) session every time it’s run. Subshells will be interactive but not login shells, of course. But this is not the place to discuss that… if I care I’ll take it up at AOSP via Gerrit.

0
8

By default stock Android mksh uses this config file: /system/etc/mkshrc

3

To update the PATH variable inside a running adb shell you can use the expect command. This works on a non-rooted phone where you can't edit system files as suggested in the other answers.

Put the following script somewhere on the path of your development machine, for example in ~/bin/adb-shell-busybox:

#!/usr/bin/expect --
spawn adb shell
expect "$" {
    sleep 0.1
    send "export PATH=/data/data/burrows.apps.busybox/app_busybox/:\$PATH\n"
}
interact

You can also inject any other setup commands that you might need.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .