« Creating jQuery UI Tabs | Home | WP No-bot Question plugin for WordPress »
Compiling GNU Bash 4.x for Android 2.x
By admin | September 4, 2011
Updated (2012-02-04): Updated to Bash 4.2 and included source code used to compile.
GNU Bash (the GNU Bourne Again Shell) is the standard shell on most desktop and server distributions of Linux. As a result, we can download bash source code and compile the Bash shell for use on Android devices to replace default /bin/sh and busybox sh. Since the Android NDK doesn’t support the full glibc library (it lacks /etc/group and friends), a small patch is required to compile Bash for Android 2.x devices (probably caused by changes since Android 1.5.x).
If you don’t feel like compiling from scratch you can download a pre-built version.
Prerequisites
- Android NDK set-up and functioning
- Bash source (wget http://mirror.csclub.uwaterloo.ca/gnu/bash/bash-4.2.tar.gz)
- Host system development headers, etc (build-essential)
- Android Bash patch
Once your prerequisites are set up and functioning properly (adjust all paths as required, such as ndk path):
export ANDROID_NDK=/opt/android-ndk-r7 export CC="${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=${ANDROID_NDK}/platforms/android-5/arch-arm/" patch -p0 < bash-android.patch ./configure --host=arm-linux --enable-static-link --without-bash-malloc --disable-rpath --disable-nls
Once that is done, open Makefile and add -static to CFLAGS so it looks like so: “-g -O2 -static”
make file bash # bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
You will find bash sitting in the folder. Now you can deploy it and try it through adb or something similar:
adb push bash /data/local/bin/bash adb -d shell $ /data/local/bin/bash bash-4.2$ /data/local/bin/bash --version GNU bash, version 4.2.0(2)-release (arm-unknown-linux-gnu) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. bash-4.2$
Of course, once you have it ready and set up you should probably create a “.bashrc” file to make the terminal a bit more bearable, if you wish to.
If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!
Topics: Mobile | 9 Comments »
December 26th, 2011 at 23:06
What version of BASH was this patch suppose to be run against?
Running the patch against Bash 4.1 fails…
January 2nd, 2012 at 16:34
@Stephen:
Try bash-4.0.0(9) release as indicated in the screenshot above. I should probably try to find that tarball that I used…
February 2nd, 2012 at 17:37
where is the source ???????
February 4th, 2012 at 17:38
@bob:
Post has been updated to a newer version of bash with sources 🙂
March 16th, 2012 at 12:57
Will it run on froyo 2.2? (it’s in uberoid 11 beta 3)
March 22nd, 2012 at 22:12
@2.2 enough:
It should run on all versions of Android, as far as I am concerned.
November 1st, 2024 at 19:48
… [Trackback]
[…] Find More on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]
November 6th, 2024 at 21:58
… [Trackback]
[…] Read More to that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]
November 19th, 2024 at 02:03
… [Trackback]
[…] Here you can find 57943 more Information on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]