Hey fellows!
It's kind of unfortunate that Termux can't execute scripts with standard shebang lines.
One option is to patch all my scripts with new shebang lines that work in Termux, but a nicer solution occurred to me: the shell(s) could be patched to automatically translate /bin and /usr/bin into Termux's bin locations.
I haven't looked into doing this yet -- just thought I'd throw the idea out there and see if there were any better ideas.
Thanks, that an interesting suggestion! Will look into how feasible it would be.
For now, one has to use the termux-fix-shebang script to manually rewrite shebang files before executing them.
That doesn't work so well on all shebangs. For example #!/usr/bin/env bash
doesn't point to env after termux-fix-shebang because env is in the applets
subdirectory.
For example #!/usr/bin/env bash doesn't point to env after termux-fix-shebang because env is in the applets subdirectory.
The bin/applets/env is from busybox, install the full coreutils bin/env with:
apt install coreutils
With that said, it would still be great not having to run termux-fix-shebang at all and patch shells as suggested by @epitron, if possible without unreasonable complexity.
apt install coreutils
Cool, thanks.
is making /usr/bin a symlink to /bin feasible? arch linux does this the other way (/bin --> /usr/bin)
@franciscod If the device is rooted then /bin or /usr/bin should be able to be setup with symlinks.
For non-root situations I'm closing this in favour of https://github.com/termux/termux-packages/issues/111 for discussion about fakechroot/proot.
This issue has been closed in favor of another closed one :)
I am a developer and I try to write a bash script as part of the software I'm developing; everything is in a git repo.
Right now, I have to make two copies of this script, and manually keep them in sync OR run termux-fix-shebang on a copy after each change to the original script.
I suggest re-opening, otherwise I don't have the necessary skills to figure it out myself, but if you already have ideas on how this could be achieved, I could try to take a look.
Thanks for this amazing project!
Have you tried apt install proot and termux-chroot? That way you don't need sheebang changes.
After an apt update and an apt upgrade I installed proot but could not install termux-chroot:
$ apt install termux-chroot
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package termux-chroot
I'm not using a rooted Android, and proot was not sufficient. Thanks for the idea though.
termux-chroot is part of proot, so you should have it installed already
I don't think so... Here's the output of apt list items starting with termux:
termux-api/stable 0.20 aarch64
termux-elf-cleaner/stable 1.1 aarch64
termux-tools/stable,now 0.29 all [installed]
It's not a separate package, just a script bundled with proot. Just try running termux-chroot after installing proot
It is not for a rooted phone it is the opposite. It provides just regular linux root system even within non-rooted system. After running termux-chroot you have all executables where they are usually in linux distros. Look where That wasn't true because how sh is with which sh before and after for comparison.PATH is but it can also be seen in /usr/bin/sh after termux-chrooting
It's working! The output of which sh did not change but the desired outcome is there :)
Thank you, that will be very, very useful in the future!
I just tried termux-chroot, and I wasn't able to access my device's storage (photos, screenshots, downloads, etc.). Is there a workaround for that?
yes, run termux-setup-storage (from outside of termux-chroot). This will setup symlinks in the storage folder, which will work in proot.
Ah! Nice! This is a decent solution to the shebang problem. Thanks!
@Neo-Oli , why not just simply symlinkig /sdcard/emulated/0 -> ~/storage ? Seems to work... Also, perhaps termux-chroot could do it automagically by default (or using some option).
termux-chroot works. However I noticed every command takes a while to run.
-bash-4.4$ time ls /storage/emulated/0 >/dev/null
real 0m0.049s
user 0m0.017s
sys 0m0.013s
-bash-4.4$ termux-chroot
bash-4.4$ time ls /storage/emulated/0 >/dev/null
real 0m1.555s
user 0m0.020s
sys 0m0.013s
Can this be rectified?
I m not able to run metasploit in my termux after giving command ./msfconsole it showing .Segmentation faultetasploit Framework consoLe.... Plzzzz help
Most helpful comment
Have you tried
apt install prootandtermux-chroot? That way you don't need sheebang changes.