lua命令lua-e“;打印(“hello”)输出为零
当我在linux shell中编写“lua-e”print(“hello”)”,但输出为:nil,lua命令lua-e“;打印(“hello”)输出为零,lua,sh,Lua,Sh,当我在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(“he
“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解析的影响
lua -e "print(1)" --output: 1
lua -e "print("hello")" --output: nil