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.

Prerequisites

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.

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

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

  1. Stephen Says:
    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…

  2. admin Says:
    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…

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

    where is the source ???????

  4. admin Says:
    February 4th, 2012 at 17:38

    @bob:

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

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

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

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

    @2.2 enough:

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

  7. slot999 Says:
    February 27th, 2022 at 18:56

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  8. Anonymous Says:
    March 28th, 2022 at 13:20

    … [Trackback]

    […] Info to that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  9. digital transformation and cloud computing Says:
    April 23rd, 2022 at 04:09

    … [Trackback]

    […] There you will find 63908 additional Information on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  10. สล็อตวอเลท Says:
    May 29th, 2022 at 20:09

    … [Trackback]

    […] Find More on on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  11. buy mastercard gift card with crypto anonymous 11 Says:
    May 31st, 2022 at 17:35

    … [Trackback]

    […] Read More Information here on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  12. sbo Says:
    June 2nd, 2022 at 18:48

    … [Trackback]

    […] Read More Info here on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  13. pg slot เว็บตรง แตกไว Says:
    July 11th, 2022 at 10:23

    pg slot เว็บตรง แตกไว สล็อตน่าเล่น มีเกม สล็อต เว็บไซต์ตรง แจกเครดิตฟรี ให้เลือกเล่นล้นหลามมากมายแบบอย่าง เสมือนเลียนแบบแหล่งคาสิโนจากสถานที่จริงๆมาไว้บนโทรศัพท์เคลื่อนที่

  14. sbo Says:
    August 10th, 2022 at 11:27

    … [Trackback]

    […] Find More on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  15. ดูหนัง Says:
    August 11th, 2022 at 18:46

    … [Trackback]

    […] Find More on on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  16. cc dumps Says:
    September 30th, 2022 at 07:35

    … [Trackback]

    […] Information to that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  17. sbo Says:
    October 3rd, 2022 at 01:01

    … [Trackback]

    […] Find More Info here to that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  18. mp3 juices Says:
    October 9th, 2022 at 09:26

    … [Trackback]

    […] Information to that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  19. maxbet Says:
    November 2nd, 2022 at 22:16

    … [Trackback]

    […] There you will find 86091 additional Information on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  20. Energy Texas Says:
    November 9th, 2022 at 18:36

    … [Trackback]

    […] Find More on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  21. keltec 223 bullpup Says:
    November 18th, 2022 at 01:51

    … [Trackback]

    […] Find More Information here to that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  22. Residual income opportunities Says:
    December 9th, 2022 at 19:22

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  23. follower instagram Says:
    December 13th, 2022 at 14:10

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

  24. yabo.club Says:
    January 20th, 2023 at 18:11

    … [Trackback]

    […] Find More to that Topic: compdigitec.com/labs/2011/09/04/compiling-bash-for-android-2-x/ […]

Comments