Closed superbonaci closed 4 months ago
#!/usr/bin/env
shebangs are already supported through termux-exec
's shebang fix mechanism.
Since Android does not permit regular applications to write to system directories we need to translate interpreter directives (shebangs) anyway.
As such #!/usr/bin/env
becomes #!/data/data/com.termux/files/usr/bin/env
But do I need to manually run termux-exec
or is already being taken care of with default installation?
It is a core termux utility and should be part of the default installation.
Not installed:
~ $ termux-exec
No command termux-exec found, did you mean:
Command termux-nfc in package termux-api
Command termux-open in package termux-tools
Command termux-x11 in package termux-x11-nightly from the x11-repo repository
It is not a command.
It's a library, not a command. https://github.com/termux/termux-exec
But I have it installed, how is it supposed to work, can I use regular scripts with the shebang #!/usr/bin/env
?
~ $ pkg install termux-exec
Checking availability of current mirror:
[*] https://mirrors.de.sahilister.net/termux/termux-main: ok
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
termux-exec is already the newest version (1:1.0).
The following packages were automatically installed and are no longer required:
binutils binutils-bin binutils-libs gettext
gnutls googletest libcroco libice libsm
libtasn1 libxcursor libxfixes libxrandr
libxt p11-kit unbound xorg-util-macros
xorgproto
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Dark syscall interception magic. Honestly beyond me, but the whole program is only 238 lines of C.
What is your android version?
I'm testing it in Android 12. The shebang #!/usr/bin/env
works when inside the script, however is not found directly, is that ok?:
#!/usr/bin/env bash
echo "abc"
~ $ ./run_check.sh
abc
~ $ type -a /usr/bin/env
bash: type: /usr/bin/env: not found
I'm testing it in Android 12. The shebang
#!/usr/bin/env
works when inside the script, however is not found directly, is that ok?:
Well no.
It wouldn't be.
That's why we have the execve()
shim.
env
is at /data/data/com.termux/files/usr/bin/env
If you want that is a more Shell variable-ish way,
it's at $PREFIX/bin/env
, which is listed in the $PATH
variable,
thus your shell knows to search that directory for executables when trying to run a command from the command-line.
termux-exec
modifies the shebang at call-time so that "off the shelf" scripts can work on Termux.
Since a shebang does not perform a $PATH search
(The main reason for using a #!/usr/bin/env
shebang is that env command_name
does that $PATH search)
The PATH in my Termux is only one directory:
~ $ echo $PATH
/data/data/com.termux/files/usr/bin
Yes, since we don't get any of the standard UNIX-like utilities handed to us from Android in any useful or consistent way.
The /usr/bin
directory and /usr/bin/env
file does not exist on Android, that's why you won't find its info. Only when you execute a file with a path or its in shebang, the /usr/bin
and /bin
prefixes are replaced with /data/data/com.termux/files/usr/bin
.
Note that /bin
is a symlink to /system/bin
and /bin/env
does exist on Android, but that is the one provided by Android itself with toybox
, not by Termux, at /system/bin/env
.
Do not try to check existence or type of /usr/bin/*
files, that will fail.
Check https://github.com/termux/termux-exec/blob/bb75f48d646aa0478527196f1878df53cd1a257c/site/pages/en/projects/docs/technical/index.md#linux-vs-termux-bin-paths for more info.
Problem description
Command
/usr/bin/env
is missing, it's only/bin/env
. All operating systems expect env to be in in /usr/bin/env:https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html https://www.diskinternals.com/linux-reader/usr-bin-bash/
Steps to reproduce the behavior.
Try to locate /usr/bin/env
What is the expected behavior?
Have env in location
System information