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.

6
  • /data/data/com.termux/files/usr/bin/bash is the only correct path.
    – Grimoire
    Nov 1, 2017 at 13:54
  • What are you trying to achieve?
    – Dan Hulme
    Nov 1, 2017 at 14:04
  • As in regular linux, I want to pass: /bin/bash or /usr/bin/bash in order to run scripts. But not to write 'bash' before every script name. Nov 1, 2017 at 14:28
  • Just as @DanHulme, I don't understand where the problem is. With #!/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.
    – Grimoire
    Nov 1, 2017 at 14:40
  • $ ls myscript.sh $ cat my* #!/data/data/com.termux/files/usr/bin/bash read -p ' enter what to echo ' inputs echo "u have inputed $inputs" $ myscript.sh myscript.sh: command not found Nov 1, 2017 at 14:54

3 Answers 3

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

3
  • Hey ♦, I could've appreciated had you left the chance for me... It's the 3rd time the same answer is posted.
    – iBug
    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.
    – Dan Hulme
    Nov 2, 2017 at 9:42
  • Ah sí. I see the difference now.
    – iBug
    Nov 2, 2017 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.

3
+100

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
^~~~
5
  • Still. $myscript.sh myscript.sh: command not found Nov 1, 2017 at 15:50
  • 2
    @JosefKlimuk Would you please type ./myscript.sh?
    – iBug
    Nov 2, 2017 at 3:17
  • It was answered already by Dan Hulme on 1 Nov. Nov 14, 2017 at 14:25
  • It looks like termux-fix-shebang is obsolete, since termux-exec is a better solution? If so, upvote @s-d-rausty's answer.
    – Carl Walsh
    Sep 14, 2018 at 7:41
  • @CarlWalsh I'm aware of it and upvoted already.
    – iBug
    Sep 14, 2018 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .