Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
bc54
Old
(Last edited by bc54; 4th September 2011 at 09:47 PM.)
#1  
Member - OP
Thanks Meter 7
Posts: 32
Join Date: Aug 2010
Default [BASH][CWM] BASH shell for android, credit: nubecoder

First off, all credit goes to nubecoder. Original post:
[Bash] android_bash: Bash, cross-compiled and modified for the android platform.

Introduction...
Most (All) modern Linux distributions utilize bash (Bourne Again SHell) rather than sh (Bourne SHell). Android, by default uses sh. Bash has numerous advantages over sh, sush as tab completion and history support.

Some ROM developers include bash in their ROMs by default. It makes adb, terminal, and scripted commands much easier and more powerful/flexible. I noticed that Sidekick 4G ROMs don't come with bash, hence this thread.

How to Install BASH...
Simpy flash this zip through Clockworkmod recovery: (if ORANGE, check mounts. Not sure if neccessary, but it doesn't hurt)
android_bash-4.1.11(2)_installer-SK4G.zip
Then load your preffered terminal emulator application, type bash, press enter, and there you go.

What's the difference between the SK4G version, and the original Epic 4G version?

Quote:
- Modified device/product check in updater-script to "SGH-T839"
- Modified $PATH variable in /data/local/.profile to "/sbin:/system/bin:/system/xbin:/data/local/tmp:/bin"
- Modified $PATH variable in /system/etc/bash.bashrc to "/sbin:/system/bin:/system/xbin:/data/local/tmp:/bin"
- [Personal preference] Add alias su='su -c bash' to /data/local/.bash_aliases
- [Personal preference] Modified $PS1 to PS1="\[$txtgrn\]\w $ \[\e[m\]"
- [Personal preference] Modified root $PS1 to PS1="\[$txtred\]\w # \[\e[m\]"
- [Personal preference] Modified location of .bash_history from /sdcard/.bash_history to /data/local/.bash_history
As any experienced bash user should know, if you want to revert/modify my personal preferences, just modify "/data/local/.bashrc", "/data/local/.bash_aliases", or "/system/etc/bash.bashrc" to your liking.

Extras...
Quote:
mntsystem Make /system partition read-only or read-write. Usage:
# mntsystem [ro|rw|status]
Unzip mntsystem.zip, copy mntsystem to /system/bin, chmod 744 /system/bin/mntsystem
Quote:
defaultshell Replace sh with bash, or revert. Usage:
# defaultshell [bash|sh|current]
Unzip defaultshell.zip, copy defaultshell to /system/bin, chmod 744 /system/bin/defaultshell
More extras (bash scripts) to come! Please post you own as well!!

PS: I was confused on where I should post this (General vs. Development), figured it isn't "technically" ROM related, so I posted in General. Please move if necessary. Thanks.
The Following 3 Users Say Thank You to bc54 For This Useful Post: [ Click to Expand ]
 
bc54
Old
#2  
Member - OP
Thanks Meter 7
Posts: 32
Join Date: Aug 2010
mntsystem extra added!
 
nteleky
Old
#3  
Junior Member
Thanks Meter 1
Posts: 7
Join Date: Dec 2008
Location: Milwaukee
Default Awesome

Oh man, I have been missing BASH so much, thank you! Now I will finally have a fully-functioning terminal on my phone. I can't wait to tab-complete (seriously).

One question about installation, though. I'm supposed to "install zip from sdcard" in CWM, correct? Will this replace anything I already have, or just copy over the files for BASH? Does it leave sh as the default shell?
 
bc54
Old
#4  
Member - OP
Thanks Meter 7
Posts: 32
Join Date: Aug 2010
Quote:
Originally Posted by nteleky View Post
I'm supposed to "install zip from sdcard" in CWM, correct? Will this replace anything I already have, or just copy over the files for BASH? Does it leave sh as the default shell?
Yes, flash through Clockworkmod. And, no it will not replace any files already on your phone (unless you already have bash, or some bash configuration files on your phone). Yes, it will leave sh as the default shell.

I can make a bash script to "replace" sh with bash, and post in the Extras if you want. When I say "replace", I mean backup /system/bin/sh, then symlink bash to /system/bin/sh. Therefore any time you try to execute a script through sh, it actually is executed by bash.

Although, for your information bash is/should-be fully backwards compatible with any sh script. I say should be, because:
Quote:
Originally Posted by Bash (Unix shell) - Wikipedia, the free encyclopedia
The vast majority of Bourne shell scripts can be executed by Bash without modification, with the exception of Bourne shell scripts stumbling into fringe syntax behavior interpreted differently in Bash or attempting to run a system command matching a newer Bash builtin, etc.
Very rare chance though.

I personally keep sh as the default though, android system level scripts are designed for sh (its works), I just use bash for any script that I decide run (through a shell, or adb). So, I start connectbot with a profile that runs "/system/bin/bash" automatically at start.
 
bc54
Old
#5  
Member - OP
Thanks Meter 7
Posts: 32
Join Date: Aug 2010
New extra!

Quote:
defaultshell Replace sh with bash, or revert. Usage:
# defaultshell [bash|sh|current]
Unzip defaultshell.zip, copy defaultshell to /system/bin, chmod 744 /system/bin/defaultshell
 
alexzutzu
Old
#6  
Junior Member
Thanks Meter 0
Posts: 4
Join Date: Sep 2011
Hey

I'm a noob and I'm curious if this could run on my galaxy s 2 running stock?
 
bc54
Old
#7  
Member - OP
Thanks Meter 7
Posts: 32
Join Date: Aug 2010
The bash binary (with supporting files) should work on any rooted android device, however the flashable zip file I posted WILL ONLY WORK on the sidekick 4g.

If you want to install bash, you can download the flashable zip, extract it and copy the the files to their correct location (Quick, easy solution), or you can modify the update-script to work with your phone. Be sure the mounts are the same! Then alter the device check. (More difficult at first, but results in easily reuseable and distributable, flashable zip)

Sent from my SGH-T839 using XDA App
 
HC13
Old
#8  
Senior Member
Thanks Meter 5
Posts: 132
Join Date: Aug 2011
hey after I go to the emulator and type bash.. what should it read?

Sent from my SGH-T839 using XDA App
 
bc54
Old
#9  
Member - OP
Thanks Meter 7
Posts: 32
Join Date: Aug 2010
Should be a green prompt that reads:

/ #

If you cd to, for example, to /sdcard, then the prompt will read:

/sdcard #

If you enter su, then the prompt will become red and use a $ instead of #.

If your prompt says sh-4.1 # then you invoked bash as sh, ie you symlinked (or renamed) bash to sh (usually /system/bin/sh).

Sent from my SGH-T839 using XDA App
 
HC13
Old
#10  
Senior Member
Thanks Meter 5
Posts: 132
Join Date: Aug 2011
well when i enter bash this comes up... 0:@localhost:// $
and the last two are green ..

 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...

XDA PORTAL POSTS

Auto Test Your Android Apps with Robotium

You’ve just finished coding your very first app, but before you release it to the wild, you … more

Open Source CPU Info App for Windows

So you’re playing with your shiny new Windows 8 tablet PC, when one of your like-minded geeky … more

Guide to Using Adobe Air on Android

When writing an app with performance in mind, you most likely want to write it native code using the … more