Shell .profile or /etc/profile for old android 2.3.3 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.
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 175ﬀ. only if argv[0] starts with a hyphen-minus is the shell considered a login shell. However, a few lines below (lines 185ﬀ.) 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.