lua命令 lua -e "print("hello")" 的输出为空

lua -e "print(1)"  --输出: 1
lua -e "print("hello")" --输出: 空

当我在Linux终端中输入'lua -e "print("hello"))"'时,输出为空,而'lua -e "print(1)"'的输出为1,这让我感到困惑。

我该如何在终端上打印出"hello"?

点赞
用户6834680
用户6834680

lua -e "print("hello")" 在 shell 中的语法和 lua -e 'print(hello)' 相同,因为 shell 会解析引号。Shell 将你的参数解释为 3 个字符串的连接:"print("hello")"

所以,Lua 输出的是全局变量 hello,其值为 nil

尝试使用 lua -e 'print("hello")' 来避免 shell 解析引号。

2017-09-21 10:51:43