即使在使用 termux-fix-shebang 后,Termux 也会报告 bash“没有这样的文件或目录”

问题描述 投票:0回答:1

我试图在 Termux 中运行一个非常简单的“Hello world”批处理脚本,但它报告错误

line 1: #!/data/data/com.termux/files/usr/bin/env: No such file or directory

这是脚本,另存为

test.sh
:

#!/data/data/com.termux/files/usr/bin/env bash
echo "Hello World"

shebang 行(上面)已使用 termux-fix-shebang 修复(文件修改时间戳在运行时已更新)。

Termux-exec 也已安装并且是最新的(尽管似乎仍然无法与标准

#!/bin/bash
shebangs 一起使用)

当我尝试在命令行中输入

bash test.sh
来运行脚本时,它显示:

test.sh: line 1: #!/data/data/com.termux/files/usr/bin/env: No such file or directory
Hello World

我想我应该松一口气,因为“Hello World”确实显示了,但是是什么导致了第 1 行的错误呢?我该如何摆脱它?

(我已经从 Stack Overflow 上的其他类似问题和答案中得到了一些建议 - 如果我错过了一些东西,我深表歉意!)

编辑:根据注释中的要求添加输出(此处,以便格式可读)

~/.../journal/nginx_config $ od -t x1 <test.sh
0000000 ef bb bf 23 21 2f 64 61 74 61 2f 64 61 74 61 2f
0000020 63 6f 6d 2e 74 65 72 6d 75 78 2f 66 69 6c 65 73
0000040 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 62 61 73
0000060 68 0a 65 63 68 6f 20 22 48 65 6c 6c 6f 20 57 6f
0000100 72 6c 64 22
0000104
~/.../journal/nginx_config $ type env
env is /data/data/com.termux/files/usr/bin/env
~/.../journal/nginx_config $
android bash termux termux-linux
1个回答
0
投票

test.sh 文件以 UTF-8 BOM 格式保存。当以无 BOM 的 UTF-8 格式保存时,它可以正常工作。感谢 @oguz-ismail 帮助识别评论中的问题(上面)👍

© www.soinside.com 2019 - 2024. All rights reserved.