Created
November 29, 2011 23:04
-
-
Save jesboat/1407050 to your computer and use it in GitHub Desktop.
Roughly equivalent to "find .", only in less-than-POSIX ash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/system/bin/sh | |
stat() { | |
local lsout="$(ls -ld "$1" 2>/dev/null)" | |
case "$lsout" in | |
"") nex=1; fil= ; dir= ;; | |
d*) nex= ; fil= ; dir=1 ;; | |
*) nex= ; fil=1; dir= ;; | |
esac | |
} | |
nonempty() { | |
case "$1" in | |
"") return 1 ;; | |
*) return 0 ;; | |
esac | |
} | |
flagset() { | |
local vname="$1" | |
local vval="$(eval "echo \$$vname")" | |
nonempty "$vval" | |
} | |
forglob() { | |
local root="$1" | |
shift | |
for ent in "$root"/* "$root"/.*; do | |
case "$ent" in | |
*/.) true ;; | |
*/..) true ;; | |
*) | |
# If the directory's empty, the glob expanded | |
# to ".../*" which doesn't exist. Rule it out. | |
stat "$ent" | |
if ! flagset nex; then | |
cur="$ent" | |
eval "$*" | |
fi | |
;; | |
esac | |
done | |
} | |
oneent() { | |
if flagset dir; then | |
local d="$cur" | |
hasfiles= | |
forglob "$d" "hasfiles=1" | |
if flagset hasfiles; then | |
echo "$d" | |
forglob "$d" oneent | |
fi | |
else | |
echo "$cur" | |
fi | |
} | |
cur=. | |
stat . | |
oneent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The use case is
(Yes, it sounds like it's just doing an extra check for paranoia, but adb actually missed some things the first time around. Not particularly encouraging.)
This would have been a lot simpler if
toolbox
(Android's BusyBox wanna-be) had tar, or if there was an obvious way to mount a Xoom's internal memory as USB Mass Storage. But this was fun, at least.