【发布时间】:2018-03-02 15:54:08
【问题描述】:
lua -e "print(1)" --output: 1
lua -e "print("hello")" --output: nil
当我在 linux shell 中写 'lua -e "print("hello"))"' 时,输出为:nil,
'lua -e "print(1)"' 输出为:1,这让我很困惑。
如何在 shell 上打印“hello”?
【问题讨论】:
lua -e "print(1)" --output: 1
lua -e "print("hello")" --output: nil
当我在 linux shell 中写 'lua -e "print("hello"))"' 时,输出为:nil,
'lua -e "print(1)"' 输出为:1,这让我很困惑。
如何在 shell 上打印“hello”?
【问题讨论】:
lua -e "print("hello")" 写在 shell 中与 lua -e 'print(hello)' 相同,因为 shell 会解析引号。 Shell 将您的参数解释为 3 个字符串的串联:"print("、hello 和 ")"。
因此,Lua 打印出全局变量 hello,即 nil。
尝试lua -e 'print("hello")' 保护引号免受shell 解析。
【讨论】: