<转> 如何在安卓设备上跑shell脚本

原文:
http://www.pctips4u.com/2016/03/writing-shell-scripts-in-android.html

Have you ever wanted to be free from performing tedious tasks in Android? Have you ever wanted to write android shell scripts? Well you are not the only one. This article shows you how to write android shell scripts, which helps you in easing your jobs.

Android Shell Script

Uses for Shell Scripts in Android Devices
Writing the android shell scripts have various uses - taking backups of files that you save in android, archiving files stored by another application, etc. As for me, I had to rename the files and folders downloaded with a comic downloader manually and compress each folder individually. So I wrote a simple shell script, that renames the individual folders and creates archives of them.Prerequisites for running Shell Scripts in Android Devices
If your goal is to write a shell script making use of comprehensive utilities (such as awk, find, etc.), see the Advanced Shell Scripting subsection.
Or else, if you just want to write simple shell scripts, see the Simple Shell Scripting subsection.Advanced Shell Scripting in Android
Since this method is aimed at providing comprehensive abilities for writing shell scripts (utilities such as awk, find, sort, etc.), this requires a rooted android device for this. Rooting an android device is an extensive process, and differs for different devices. How to root your android device is something that you will have to lookup on your own.

BusyBox and Terminal Emulator for Android Shell Script

Busy Box & Terminal Emulator for Android Shell Scripting

In your rooted android device, install an app called BusyBox. It provides most of the *nix utilities such as awk, sed, find, sort, head, etc., which will be useful when you try to write a shell script to run on Android. Then install Terminal Emulator (You can also use other similar tools, but I use Terminal Emulator).
BUSYBOX ON GOOGLE PLAY

TERMINAL EMULATOR ON GOOGLE PLAY

Simple Shell Scripting in Android
This method does not require to root your android device. Just the Terminal Emulator is required to run the shell scripts you created. Refer the link above for getting Terminal Emulator.Writing Shell Scripts in Android
You can write Shell Scripts in your PC and transfer it to your Android device, or else, write them directly on your Android device. Start writing your android shell script by using the following as the first line (Also known as Shebang)

#!/system/bin/sh

Running Shell Scripts in Android
Then save your entire script and open Terminal Emulator. Now run the script using sh command.

sh /
                    
                    

你可能感兴趣的:(<转> 如何在安卓设备上跑shell脚本)