2

Just rooted my old phone with Android 2.3.3 and I would like to define some aliases for each shell I start (with adb or terminal app). I found this question where one answer says that /etc/profile (=/system/etc/profile due to soft link /etc->/system/etc) is one of the files the shell sources on startup. But this post talks about /system/bin/sh being a link to /system/bin/mksh, which is not the case on my 2.3.3 system.

Despite the fact that strings sh produces /etc/profile as one output, the file is not sourced.

Does anyone happen to know the old Android version and whether I have a chance to get /etc/profile or some other file sourced on shell startup? I thought it might be a permission problem but even rwxrwxr-x does not help.

3

As I wrote in the other question, adb shell does not start a login shell. Only login shells read /etc/profile.

As you can see in Android 2.3.3 sh source, main.c lines 175ff. only if argv[0] starts with a hyphen-minus is the shell considered a login shell. However, a few lines below (lines 185ff.) there is code to read the content of $ENV.

So you could trick it and enter the following code after entering adb shell mode:

ENV=/etc/profile sh

You can probably use exec to replace the current shell, but this is the shortest to type I can come up with, as you will have to type it every time.


Alternatively, you can compile mksh for Android 2.3 (it works down to at least 1.5, if not older) manually (the Android.mk file is version-specific, unfortunately, so you’ll have to call Build.sh directly) and add the binary, then replace the default sh with it (I tested that first with Android 1.6; the newer the mksh version used the better, as early versions had bugs, e.g. preventing adb install from working).

Disclaimer: I’m the mksh developer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.