Alternative use of JS and Sh

by Ricardo “Rudxain” Fernández Serrata

Version 2 (December 31, 2024)

Download (767 downloads)

Showcase data processing on Javascript and Shell instead of AM, which decreases the block-count considerably.

The example expression to evaluate is 3x + 1 (where x is input), but you can change it to anything valid depending on language.

JS and MirBSD Korn Shell (MKSH) are very different languages, some expressions will have different valid syntax or the same syntax with different semantics. In this example I show you something they have in common, for the sake of simplicity.

Arithmetic results can be vastly different, because MKSH uses 32bit signed integers that wrap-around on overflow, while JS uses 64bit IEEE-754 floating-point (binary64).

Math may sometimes be faster on MKSH, but there are no `pow` nor `log` functions (unless you run `bc`, which isn't available on legacy Android versions).

Text/String processing can be done in both, but JS is considerably better than AM and MKSH combined. If the Android version is newer, you can run `awk` and `sed` scripts.

The shell can do more things than just processing, it can do file operations like creating, editing, deleting, renaming, and moving files and directories. With root (or ADB), it can also change any system setting and install more commands (such as `wget` and `curl` for HTTP and other network requests).

Dialogs have more startup latency than shell, but the shell has more latency than AM even though some computations are faster in the shell. This could be solved if AM exposed the JS-engine API: https://developer.android.com/develop/ui/views/layout/webapps/jsengine


MirBSD Korn Shell Manual: http://www.mirbsd.org/htman/i386/man1/mksh.htm

List of installed executable files and symlink binaries for each Android version: https://chromium.googlesource.com/aosp/platform/system/core/+/refs/heads/upstream/shell_and_utilities

https://developer.android.com/studio/command-line/adb#shellcommands

JS documentation can be found in the official MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference

Rudxain profile: llamalab.com/automate/community/flows/42921

LICENSE: https://unlicense.org

See also: "ArrayLang" https://llamalab.com/automate/community/flows/41151

4.9 average rating from 7 reviews

5 stars
6
4 stars
1
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.