Compdigitec Labs

« | Home | »

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.


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”

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 <>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

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.

Bash running on Android 2.x

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 | 6 Comments »

6 Responses to “Compiling GNU Bash 4.x for Android 2.x”

  1. Stephen Says:
    December 26th, 2011 at 11:06 pm

    What version of BASH was this patch suppose to be run against?

    Running the patch against Bash 4.1 fails…

  2. admin Says:
    January 2nd, 2012 at 4:34 pm


    Try bash-4.0.0(9) release as indicated in the screenshot above. I should probably try to find that tarball that I used…

  3. bob Says:
    February 2nd, 2012 at 5:37 pm

    where is the source ???????

  4. admin Says:
    February 4th, 2012 at 5:38 pm


    Post has been updated to a newer version of bash with sources :)

  5. 2.2 enough Says:
    March 16th, 2012 at 12:57 pm

    Will it run on froyo 2.2? (it’s in uberoid 11 beta 3)

  6. admin Says:
    March 22nd, 2012 at 10:12 pm

    @2.2 enough:

    It should run on all versions of Android, as far as I am concerned.