Recently we discussed how to get a shell on your Android. That only brings out the Android Shell (ash) into use. But the shell that currently dominates the POSIX world is GNU Bash. Android Shell is powerful with a host of features, yet nothing compared to Bash. In fact it is a subset on Bash, just like the original Bourne shell (sh). Fortunately enough, you can enjoy the same robustness on Bash shell on your Android too. In this post I’ll show you how to get Bash running on your android, and optionally making it the default shell, replacing ash.
But before we start our chore, let us be familiar with our friend Bash. Bash is originally a shell for UNIX and UNIX-Like environments (Macs, Linux etc.) developed by Brian Fox for the GNU Project as a free replacement for the original UNIX Bourne shell (sh) some 23 years ago back in 1989. It is used widely as the shell of choice on Linux and Mac OS X. Also, it has been successfully ported to Windows.
Bash is actually a command processor, typically run in a text window or a terminal emulator that allows the user to type commands perform certain actions. Bash can also read commands from shell scripts and execute them. Like all UNIX shells, it supports filename wildcarding, piping, here documents, command substitution, variables and control structures for condition-testing and iteration. The keywords, syntax and other basic features of the language are similar to sh and its derivatives, offering a nice interoperability with other popular shells. In addition, it supports history and command auto-complete. These features make it the shell of choice for every command-line junkie.
Since Android is Linux (I can call it Linux!), anything that works on Linux will do on Android. So will Bash. This idea was taken by one developer Mzet at xda-developers.com. He compiled entire the entire Bash shell for android target and statically linked it with its dependencies, making it a single executable.
Now, let’s bring bash to the bot. Be warned that, pushing an executable into system directories needs your device to be rooted. Unfortunately there is no workaround for this. And yes, rooting, jail-breaking and such stuff is dangerous and might brick your device. PROCEED AT YOUR OWN RISK. AT ANY MEANS BLOGZAMANA SHALL NOT BE RESPONSIBLE FOR ANY LOSS OR BRICK OF DEVICE ARISING FROM FOLLOWING THIS TUTORIAL. However, should you fall into any pits, we are there to help you. Just leave a comment, describing your problem.
- Start by downloading bash from his personal file dump. This is an executable. Since it begins with a text line (ELF, executable marker of linux), browsers may detect it as a text file and try to render it your browser. So save the link target as “bash”. Even some browsers add a “.bin” extension to the file. So, if that is the case, you will either need to rename it or use “bash.bin” in place of simply “bash”.
- If you have downloaded into your computer, transfer the file into your device. Note the path of the file you transferred.
- Open a command terminal, either adb or an android terminal emulator. Elevate into super user by typing
- Mount /system directory in read-write mode. By default /system is mounted in read-only mode. You cannot write anything in this mode.
mount -o remount,rw /system
- Push the file into your /system/bin directory. You can either copy it using a file manager or by using adb (Android Debug Bridge) by elevating adb or a shell:
cp <path to bash executable> /system/bin
- CD to system/bin ditectory
- Change the permissions of bash executable to allow execution by any user and modification by super user (root).
chmod 0755 bash
This is it. You have now successfully installed bash in your android device. Get set and explore bash.
To get into bash, type the following in the terminal
After you’re done type
to close bash and
again to close the terminal.
If you wanna make Bash your default shell, replacing your default shell then, you need to do some additional task.
- Fire up a terminal and elevate to root.
- CD to /system/bin directory.
- Create a symlink to bash in the name sh to replace the existing link to ash by typing the following:
mv sh sh0
ln -s bash sh
In case you wanna revert, cd to /system/bin and remove the existing symlink
mv sh0 sh
and optionally bash.
Stay tuned to BlogZamana for some more exciting android tips and tricks.Credits: mzet at xda-developers.com