Regular paths for bash do not work in termux app. I tried: /usr/bin/bash and /bin/bash Also 'whereis' command gives the following output: $ whereis bash bash: /data/data/com.termux/files/usr/bin/bash But this path also is not correct. So, I have to run every bash script with the word 'bash' before it. And cannot run bash scripts without it.
3 Answers
In September 2017 the maintainer of Termux released a package termux-exec, which wraps up execve(2) so that files that has a shebang line like #!/bin/sh or #!/usr/bin/env will run correctly in Termux. Just run
pkg install termux-exec
and restart Termux (or open a new session). You'll now be able to run #!/bin/sh scripts.
The previous solution was as following:
Termux provides a handy utility
termux-fix-shebangWhose description reads:
Rewrite shebangs in specified files for running under Termux, which is done by rewriting
#!*/bin/binaryto#!$PREFIX/bin/binary.Just apply it to the scripts you wish to run. It does what its name suggests: fix the shebang line
#!/xxxof your script files. It can also fix other scripts like Perl or Python.
Also note that by default your working directory is not in $PATH, so you cannot directly type myscript.sh, but instead
./myscript.sh
^~
... or explicitly specify an interpreter shell (in which case you don't need the directory prefix):
bash myscript.sh
^~~~
- 7,747
- 8
- 44
- 83
-
-
2
-
-
It looks like
termux-fix-shebangis obsolete, sincetermux-execis a better solution? If so, upvote @s-d-rausty's answer. – Carl Walsh Sep 14 '18 at 07:41 -
If myscript.sh is not in your $PATH, you need to run it by its path, not its basename. Assuming you're in the same directory as the script, run
./myscript.sh
Note the leading ./
- 35,000
- 17
- 90
- 155
-
Hey ♦, I could've appreciated had you left the chance for me... It's the 3rd time the same answer is posted. – iBug Nov 02 '17 at 03:53
-
@iBug You certainly deserve the credit for digging into the problem. I looked and Josef's comment made it obvious what his mistake was. I was going to comment under your answer to suggest this but realised I was really writing an answer. – Dan Hulme Nov 02 '17 at 09:42
-
Install termux-exec. It's a new utility that should resolve your $PATH issue. Termux-exec allows you to execute scripts with shebangs for traditional Unix file structures. See https://wiki.termux.com/wiki/Termux-exec for more information.
- 161
- 1
- 7
/data/data/com.termux/files/usr/bin/bashis the only correct path. – Grimoire Nov 01 '17 at 13:54#!/data/data/com.termux/files/usr/bin/bashas the script's first line, it's then possible to execute the script by just/path/to/the/script.sh. – Grimoire Nov 01 '17 at 14:40$ myscript.sh myscript.sh: command not found
– Josef Klimuk Nov 01 '17 at 14:54