What is the most reliable way to detect if a script is running on Android (instead of a regular Linux build)?

To run scripts, I'm using bash, the Terminal app, and BusyBox.

2 Answers 2


To do this, we need the code below in a file somewhere on the Android device (in /data/checkdroid for example):

ANDROID_BUSYBOX_APPLETS="acpid add-shell addgroup adduser adjtimex arp arping ash awk base64 basename beep blkid blockdev bootchartd brctl bunzip2 bzcat bzip2 cal cat catv chat chattr chgrp chmod chown chpasswd chpst chroot chrt chvt cksum clear cmp comm conspy cp cpio crond crontab cryptpw cttyhack cut date dc dd deallocvt delgroup deluser depmod devmem df dhcprelay diff dirname dmesg dnsd dnsdomainname dos2unix du dumpkmap dumpleases echo ed egrep eject env envdir envuidgid ether-wake expand expr fakeidentd false fbset fbsplash fdflush fdformat fdisk fgconsole fgrep find findfs flock fold free freeramdisk fsck fsck.minix fsync ftpd ftpget ftpput fuser getopt getty grep groups gunzip gzip halt hd hdparm head hexdump hostid hostname httpd hush hwclock id ifconfig ifdown ifenslave ifplugd ifup inetd init insmod install ionice iostat ip ipaddr ipcalc ipcrm ipcs iplink iproute iprule iptunnel kbd_mode kill killall killall5 klogd last less linux32 linux64 linuxrc ln loadfont loadkmap logger login logname logread losetup lpd lpq lpr ls lsattr lsmod lsof lspci lsusb lzcat lzma lzop lzopcat makedevs makemime man md5sum mdev mesg microcom mkdir mkdosfs mke2fs mkfifo mkfs.ext2 mkfs.minix mkfs.vfat mknod mkpasswd mkswap mktemp modinfo modprobe more mount mountpoint mpstat mt mv nameif nanddump nandwrite nbd-client nc netstat nice nmeter nohup nslookup ntpd od openvt passwd patch pgrep pidof ping ping6 pipe_progress pivot_root pkill pmap popmaildir poweroff powertop printenv printf ps pscan pstree pwd pwdx raidautorun rdate rdev readahead readlink readprofile realpath reboot reformime remove-shell renice reset resize rev rm rmdir rmmod route rpm rpm2cpio rtcwake run-parts runlevel runsv runsvdir rx script scriptreplay sed sendmail seq setarch setconsole setfont setkeycodes setlogcons setserial setsid setuidgid sh sha1sum sha256sum sha3sum sha512sum showkey slattach sleep smemcap softlimit sort split start-stop-daemon stat strings stty su sulogin sum sv svlogd swapoff swapon switch_root sync sysctl syslogd tac tail tar tcpsvd tee telnet telnetd test tftp tftpd time timeout top touch tr traceroute traceroute6 true tty ttysize tunctl udhcpc udhcpd udpsvd umount uname unexpand uniq unix2dos unlzma unlzop unxz unzip uptime users usleep uudecode uuencode vconfig vi vlock volname wall watch watchdog wc wget which who whoami whois xargs xz xzcat yes zcat zcip"

checkAndroid() {
    [ ! -e "/system/bin/adb" ] && return
    if ! type $ANDROID_BUSYBOX >/dev/null 2>&1; then
        echo "FAILED! this program needs busybox to work on Android" 1>&2
        exit 1
        eval "alias '$i=$ANDROID_BUSYBOX $i'"

Here is an usage example of this fixture:

source "/data/checkdroid"
echo "ANDROID_HOST=$ANDROID_HOST" && type rdate
# output:
# rdate not found
echo "ANDROID_HOST=$ANDROID_HOST" && type rdate
# output:
# rdate is an alias for '/system/bin/busybox rdate'

Source: https://gist.github.com/enten/67c4e332908b248a59a9

  • 1
    Please clarify the usage of your script.
    – GiantTree
    Commented Jan 4, 2015 at 16:20

To determine if the script itself is running on an Android device or another flavor of Linux use getprop to detect if the script is running on Android instead of regular Linux.

If you want to use the getprop command in a script to determine which version of Android is installed, use getprop ro.build.version.release. It will look something like COMMANDIF="$(command -v getprop ro.build.version.release)" in a script. Source reference https://github.com/TermuxArch/TermuxArch/blob/master/setupTermuxArch.bash#L657 example.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .