Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lua command lua -e "print("hello") output is nil

Tags:

sh

lua

lua -e "print(1)"  --output: 1
lua -e "print("hello")" --output: nil

When i write 'lua -e "print("hello"))"' in linux shell,but is output was:nil,
'lua -e "print(1)"' output was:1,this make me confused.
How can I print "hello" on the shell?

like image 211
hys Avatar asked Jan 01 '26 18:01

hys


1 Answers

lua -e "print("hello")" written in shell is the same as lua -e 'print(hello)' due to parsing quotes by the shell. Shell interprets your argument as concatenation of 3 strings: "print(", hello and ")".
So, Lua prints global variable hello which is nil.
Try lua -e 'print("hello")' to protect quotes from shell parsing.

like image 166
Egor Skriptunoff Avatar answered Jan 06 '26 01:01

Egor Skriptunoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!