{"id":230,"date":"2011-09-04T16:33:51","date_gmt":"2011-09-04T21:33:51","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=230"},"modified":"2012-02-04T17:27:39","modified_gmt":"2012-02-04T22:27:39","slug":"compiling-bash-for-android-2-x","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2011\/09\/04\/compiling-bash-for-android-2-x\/","title":{"rendered":"Compiling GNU Bash 4.x for Android 2.x"},"content":{"rendered":"<p><strong>Updated (2012-02-04):<\/strong> Updated to Bash 4.2 and included source code used to compile.<\/p>\n<p>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 <a title=\"Android NDK\" href=\"http:\/\/developer.android.com\/sdk\/ndk\/index.html\">Android NDK<\/a> doesn&#8217;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 <a href=\"http:\/\/www.kbrandt.com\/2009\/06\/how-to-cross-compile-the-bash-shell-for-android-15.html\">changes since Android 1.5.x<\/a>).<\/p>\n<p>If you don&#8217;t feel like compiling from scratch you can download <a title=\"Pre-built Bash for Android\" href=\"\/labs\/files\/bash-android.7z\">a pre-built version<\/a>.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<ul>\n<li><strong><\/strong>Android NDK set-up and functioning<\/li>\n<li>Bash source (wget <a href=\"http:\/\/mirror.csclub.uwaterloo.ca\/gnu\/bash\/bash-4.2.tar.gz\">http:\/\/mirror.csclub.uwaterloo.ca\/gnu\/bash\/bash-4.2.tar.gz<\/a>)<\/li>\n<li>Host system development headers, etc (build-essential)<\/li>\n<li><a title=\"Android Bash patch\" href=\"\/labs\/files\/bash-android.patch\">Android Bash patch<\/a><\/li>\n<\/ul>\n<p>Once your prerequisites are set up and functioning properly (adjust all paths as required, such as ndk path)<strong>:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nexport ANDROID_NDK=\/opt\/android-ndk-r7\r\nexport CC=&quot;${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\/&quot;\r\npatch -p0 &lt; bash-android.patch\r\n.\/configure --host=arm-linux --enable-static-link --without-bash-malloc --disable-rpath --disable-nls\r\n<\/pre>\n<p>Once that is done, open Makefile and add -static to CFLAGS so it looks like so: &#8220;-g -O2 -static&#8221;<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmake\r\nfile bash\r\n# bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped\r\n<\/pre>\n<p>You will find bash sitting in the folder. Now you can deploy it and try it through adb or something similar:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nadb push bash \/data\/local\/bin\/bash\r\nadb -d shell\r\n$ \/data\/local\/bin\/bash\r\nbash-4.2$ \/data\/local\/bin\/bash --version\r\nGNU bash, version 4.2.0(2)-release (arm-unknown-linux-gnu)\r\nCopyright (C) 2011 Free Software Foundation, Inc.\r\nLicense GPLv3+: GNU GPL version 3 or later &lt;http:\/\/gnu.org\/licenses\/gpl.html&gt;\r\n\r\nThis is free software; you are free to change and redistribute it.\r\nThere is NO WARRANTY, to the extent permitted by law.\r\nbash-4.2$\r\n<\/pre>\n<p>Of course, once you have it ready and set up you should probably create a &#8220;.bashrc&#8221; file to make the terminal a bit more bearable, if you wish to.<\/p>\n<div id=\"attachment_231\" style=\"width: 250px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.compdigitec.com\/labs\/wp-content\/uploads\/2011\/09\/bash-android.png\"><img aria-describedby=\"caption-attachment-231\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-231\" title=\"Bash running on Android\" src=\"http:\/\/www.compdigitec.com\/labs\/wp-content\/uploads\/2011\/09\/bash-android.png\" alt=\"\" width=\"240\" height=\"320\" \/><\/a><p id=\"caption-attachment-231\" class=\"wp-caption-text\">Bash running on Android 2.x<\/p><\/div>\n<p style=\"text-align: center;\">","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[759],"tags":[760,107,13,298,761],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/230"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=230"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/230\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}