运行正常:
C:\>ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Hi #[pressed ENTER]
[pressed ENTER]
Hi # <~~ here Hi came as the output, as expected.
here is: "\n\n" #<~~ here Hi came as the output, as expected.
C:\>
但是当我在Ubuntu机器上发生这种情况时,我感到很惊讶:
@ubuntu:~$ ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
> hi # [pressed ENTER]
> [pressed ENTER]
> hi #[pressed ENTER]
> ^C
@ubuntu:~$
有什么建议可以让它在Ubuntu中运行吗?
答案 0 :(得分:2)
在Ubuntu中对我来说非常好用:
% ruby -00 -e 'a = gets; puts a; puts "here is #{$/.inspect}"'
hi
hi
here is "\n\n"
看起来你只是错过了命令中的最后一个单引号。