Tuesday, December 18, 2012

How to - execute shell scripts on your Android phone

Hi All,

This post explains how to run simple shell scripts on your android phone...

Assume we have a script that generates odd numbers b/w 1 to 10

Here is the script:

echo $i

while [ $i -lt 9 ]
       i=`echo $(($i+2))`
       echo $i

Type this content onto a shell (a text file with a .sh extension) using an App called TextEdit written by Paul Mach.

Save the file (test.sh) in your external sd card root folder.

Then you need a shell to run this script.

Download an app called Terminal Emulator from the Google Play store.

So we are set to run our script...


1. Open the emulator
2. Give the below commands:

     cd sdcard
     cd external_sd
     sh test.sh

3. If there are any errors, you can fix them using the TextEdit once more. Save it and re-run!!


1. This procedure will work for both rooted and not-rooted phones.
2. The script uses echo command instead of expr command.
3. Since the phone I used to run this script is not rooted - I had to save my files to the card.

Hope you enjoyed scripting on your Android,
Ananth G S

No comments:

Post a Comment