LWN.net Logo

Tasting the Ice Cream Sandwich

Tasting the Ice Cream Sandwich

Posted May 26, 2012 19:18 UTC (Sat) by djao (guest, #4263)
In reply to: Tasting the Ice Cream Sandwich by mirabilos
Parent article: Tasting the Ice Cream Sandwich

I don't understand why you say Android is not Linux. Android is a very lightly forked Linux kernel and the kernel/userspace API is almost fully compatible with GNU/Linux. In any case I used eglibc. It even works fine for system scripts that use /system/bin/sh.

I would love to make mksh work. Where do I put the .mkshrc file on my Android phone in order to make it load whenever I start the shell?


(Log in to post comments)

Tasting the Ice Cream Sandwich

Posted May 26, 2012 19:37 UTC (Sat) by mirabilos (subscriber, #84359) [Link]

> I don't understand why you say Android is not Linux.

No, Android is different userland on top of the Linux kernel, instead of eglibc or µClibc userland. In this case, mksh’s got the ability to run directly using the Android bionic libc.

As for the .mkshrc file – it depends on which mksh you use. The one included in AOSP, Android-x86 and Google Android 3 and up looks for this file in /system/etc/mkshrc and standard mksh builds in ~/.mkshrc (but the location can be overridden by setting $ENV properly).

A suitable mkshrc file for Android follows:

tg@tglase-amd64:~ $ cat android/external/mksh/mkshrc
# Copyright (c) 2010, 2012
# Thorsten Glaser <t.glaser@tarent.de>
# This file is provided under the same terms as mksh.
#-
# Minimal /system/etc/mkshrc for Android
#
# Support: https://launchpad.net/mksh

: ${TERM:=vt100} ${HOME:=/data} ${MKSH:=/system/bin/sh} ${HOSTNAME:=$(getprop ro.product.device)}
: ${SHELL:=$MKSH} ${USER:=$(typeset x=$(id); x=${x#*\(}; print -r -- ${x%%\)*})} ${HOSTNAME:=android}
if (( USER_ID )); then PS1='$'; else PS1='#'; fi
function precmd {
typeset e=$?

(( e )) && print -n "$e|"
}
PS1='$(precmd)$USER@$HOSTNAME:${PWD:-?} '"$PS1 "
export HOME HOSTNAME MKSH SHELL TERM USER
alias l='ls'
alias la='l -a'
alias ll='l -l'
alias lo='l -a -l'

function more {
local dummy line llen curlin=0

cat "$@" | while IFS= read -r line; do
llen=${%line}
(( llen == -1 )) && llen=${#line}
(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
if (( (curlin += llen) >= LINES )); then
print -n -- '\033[7m--more--\033[0m'
read -u1 dummy
[[ $dummy = [Qq]* ]] && return 0
curlin=$llen
fi
print -r -- "$line"
done
}

function setenv {
eval export $1'="$2"'
}

for p in ~/.bin; do
[[ -d $p/. ]] || continue
[[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH
done

unset p

: place customisations above this line

Tasting the Ice Cream Sandwich

Posted May 27, 2012 4:04 UTC (Sun) by djao (guest, #4263) [Link]

Sure, Android includes a non-GNU userland and does not include the GNU userland, but the GNU userland (including even regular old glibc) will still work if you put it on the phone yourself, even though your phone doesn't come with it. There are even Play Store apps that download and install an entire Debian/Ubuntu ARM distribution in chroot on Android. I wouldn't want static binaries for everything but a shell is critical enough that I'll make an exception.

Thanks for the mkshrc script. It works fine in adb shell from /system/etc/mkshrc but doesn't seem to work in apps like Terminal Emulator (?) or ConnectBot's local terminal.

Tasting the Ice Cream Sandwich

Posted Jun 24, 2012 11:30 UTC (Sun) by mirabilos (subscriber, #84359) [Link]

Sorry, I don’t have these applications, so I don’t know about them.
This all also depends on which mksh you’re using.

Basically, mksh looks in "${ENV:-~/mkshrc}", and the path has been
changed to /system/etc/mkshrc in the in-tree AOSP version. There’s
also /etc/profile and ~/.profile…

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds