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
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 ./
-
Hey ♦, I could've appreciated had you left the chance for me... It's the 3rd time the same answer is posted.– iBugCommented Nov 2, 2017 at 3: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. Commented Nov 2, 2017 at 9:42
-
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-shebang
Whose description reads:
Rewrite shebangs in specified files for running under Termux, which is done by rewriting
#!*/bin/binary
to#!$PREFIX/bin/binary
.Just apply it to the scripts you wish to run. It does what its name suggests: fix the shebang line
#!/xxx
of 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
^~~~
-
-
2
-
-
It looks like
termux-fix-shebang
is obsolete, sincetermux-exec
is a better solution? If so, upvote @s-d-rausty's answer. Commented Sep 14, 2018 at 7:41 -
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.
/data/data/com.termux/files/usr/bin/bash
is the only correct path.#!/data/data/com.termux/files/usr/bin/bash
as the script's first line, it's then possible to execute the script by just/path/to/the/script.sh
.