[Toybox] Tilde expansion test on android?

Rob Landley rob at landley.net
Wed Jan 8 21:42:58 PST 2020


On 1/8/20 5:41 PM, enh wrote:
>> And I'm going... ok, I can get away with just saying ~ and comparing it with
>> $HOME (which I did in the previous two tests), but if I want an actual username,
>> the only one guaranteed-ish to be on the system is "root". But though root's
>> home directory has been "/root" on every Linux distro I've used for the past
>> decade, it's not actually _required_ by anything?
> 
> yeah, and it's just / for all users on Android, and /data for all uids
> that correspond to apps (which is: all uids >= 10000).

I can work with that... except it doesn't?  In the terminal app with mksh:

  $ echo ~
  /data/user/0/jackpal.androidterm/app_HOME

I do get / from echo ~root though. I can also do whoami and ~ that string to
compare against $HOME... except echo ~u0_a174 is giving me /data and $HOME is
giving me the app_HOME path. But then ~ is always basically printing out $HOME,
so it sounds like an .rc file or something set $HOME weirdly...

>> Anyway, tl;dr: ~root isn't guaranteed to expand to /root but nothing _else_ is
>> likely to consistently expand to anything, and I wanna write tilde expansion
>> tests. Suggestions?
> 
> slap in another of our "wait, is this Android?" checks and skip this
> test there? `[ $(id -u shell) -eq 2000 ]` would be an appropriately
> uid-themed check.

What _is_ a "wait, is this Android" check? (I can ANDROID_NDK in C but in a
shell script, _not_ checking ? uname -s says Linux... [ -d /system/bin ] maybe?)

Rob



More information about the Toybox mailing list