3

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.

Josef Klimuk
  • 143
  • 1
  • 1
  • 5

3 Answers3

3

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
^~~~
iBug
  • 7,747
  • 8
  • 44
  • 83
3

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 ./

Dan Hulme
  • 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
  • Ah sí. I see the difference now. – iBug Nov 02 '17 at 12:46
3

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.

S D Rausty
  • 161
  • 1
  • 7