Android runs MirBSD Korn shell mksh
by default which is mostly a superset of sh. That has some limitations compared to bash scripts, for example one can't use arrays.
Furthermore core utils are android specific toolbox or toybox applets, usage often is slightly different and sometimes limited (for example tar
)
Customized android devices use busybox as extension for missing core utils, which applets also depend on the build.
Android permissions are extended with SELinux which requires different way of scripting when it comes to file manipulation, for example one can't just use sed
as usual because the file will lose it's secontext.
one should always test scripts against as much shells as possible (mksh, ash) and keep usage of core utils simple (for example code should work with BSD grep, toybox grep and busybox grep)
Avoid interactive scripts as the device has no real keyboard and the tiny touchscreen is a hassle when it comes to command line confirmation.
Dealing with paths is also slightly different on android devices, for example shebang is #!/system/bin/sh
while /data/local/tmp
directory is persistent on user space (not in RAM)
Worth mention is adb shell it has more privileges as any other terminal emulator by default. scripts running on host using adb commands should be clearly provided as such, inexperienced users may confuse them with shell scripts running on client.
When it comes to scripts running in recovery mode there is one related script language EDIFY and it's counterpart shell script replacement. the shell in recovery mode (ash
) is different from android boot mode (mksh
) and behavior depends on recovery build. one should bundle busybox and all necessary binaries to avoid trouble with missing applets (like awk
)
The script language itself is not different and there is no specific syntax. Porting bash scripts to android is absolutely possible and requires no special knowledge. It's all just about different environment, therefore scripts should be tested on target platform
That said, Happy scripting :)