I don't know about earlier releases, but ICS has a
bash
shell in
/system/bin
. If you start a shell through
ADB (eg.
./adb shell
), it'll start
/system/bin/sh
as a shell which is a symlink to
bash
. Unfortunately ADB does not add the
-l
option to the shell's commandline, thus the shell will not be a login shell and it'll not look for _any_ configuration files.
The good news is that you just have to execute the shell again with the
-l
switch (either
sh -l
or
bash -l
) and it'll read/execute a few config files.
I've compiled
strace
to be able to get the list of actual pathes that
bash
looks in for config files.
These locations are:
/.bash_login
/.bash_logout
/.bash_profile
/.profile
/etc/profile
/system/etc/bash/bash_logout
$HOME/.bash_login
$HOME/.bash_logout
$HOME/.bash_profile
$HOME/.profile
Of course by default there's no
$HOME
variable defined. In that case
bash
looks in the root directory (the first four entries in the above list). But if you do set a
$HOME
,
bash
will look there (and not in the root dir).
To make your life easy, you could place your shell/environment settings in
/etc/profile
(aka.
/system/etc/profile
). And while you're at it, don't forget to set
$HOME
and
$USER
too. Both might come handy.
P.S.: to automate the full process, you could replace the
/system/bin/sh
symlink with a simple shell script.
Eg.
#!/system/bin/bash
exec /system/bin/bash -l
Or ...
#!/system/bin/bash
[ -f /etc/profile ] && . /etc/profile
exec /system/bin/bash
P.S.2: the problem with
bash
was discussed quite extensively in a topic at
xda-developers.com (although nobody got to the results that I've explained above), but unfortunately newly registered users are not allowed to comment in development related forums, so I couldn't share my findings there.
P.S.3: if for some reason your
/system/bin/bash
shell became setuid root (eg.
RootLogger does that), then the
bash
started by ADB won't load
/etc/profile
because at this time the shell runs as the "shell" user and the config file is owned by root. However if right after
./adb shell
you start a
su -s /system/bin/bash -l
root login shell, it'll load the config file's contents. The second variant of my
/system/bin/sh
replacement suggestions works around this problem too.
Comments
How could i modify the source code of the shell in Android ICS?
Best Regards.
Re: How could i modify the source code of the shell in Android