在 OpenWRT 上直接运行 Lua 脚本(无需先运行 lua)

在 OpenWRT 上,我有一个名为 on_new_device.lua 的 Lua 脚本,如果我执行 lua on_new_device.lua,它就能正常运行;然而,我想通过执行 ./on_new_device.lua 来运行它。

执行 ./on_new_device.lua 会返回以下错误...

root@router:~# ./on_new_device.lua
-ash: ./on_new_device.lua: not found

文件具有执行权限...

root@router:~# ls -la ./on_new_device.lua
-rwxrwxrwx    1 root     root          1094 Jun 18 11:06 ./on_new_device.lua

文件以 #!/usr/bin/lua 开始...

root@router:~# head -1 ./on_new_device.lua
#!/usr/bin/lua

我该如何直接执行这个文件?

点赞
用户2957186
用户2957186

你能把它放进一个脚本里吗?

复制以下内容到test.ash文件中:

#!/bin/ash

/usr/bin/lua /[path]/on_new_device.lua

然后对test.ash进行chmod 755操作,就可以运行:

./test.ash
2019-06-18 16:56:09
用户6728598
用户6728598
Bah, the problem was that the lua script was created on a Windows machine and had \\r\\n line endings. Saving the file with \\n line endings solved the issue.

嗯,问题是 Lua 脚本是在 Windows 机器上创建的,并且具有 \\r\\n 行尾。将文件保存为 \\n 行尾解决了该问题。

2019-06-18 18:53:24