$ echo testing > testfile
$ irb
2.5.1 :001 > IO.read('testfile')
=> "testing\n"
试图了解换行符的来源,因为它显然不在文件中.
但是新行在文件中,echo添加它.你可以用hexdump看看自己:
$ echo testing > testfile
$ hexdump testfile 
0000000 74 65 73 74 69 6e 67 0a                        
0000008
那0x0a是你的换行符.
你可以问你的shell(大概bash)echo:
$ help echo
echo: echo [-neE] [arg ...]
    Output the ARGs.  If -n is specified, the trailing newline is
    suppressed. [...]
所以,如果你说echo -n testing > testfile,你会得到你期望的结果.
| 归档时间: | 
 | 
| 查看次数: | 49 次 | 
| 最近记录: |