这是我的代码
michal@argon:~$ cat test.txt
1
2
3
4
5
michal@argon:~$ cat test.txt | while read line;do echo $line;done > new.txt
michal@argon:~$ cat new.txt
1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)
我不知道为什么命令echo $line过滤了空格字符,我希望test.txt和new.txt完全相同.
请帮忙,谢谢.
您的代码有几个问题.
$parameter在...之外" ".别.read用于$IFS将输入行拆分为单词,您必须禁用它.总结一下:
while IFS= read line ; do echo "$line" ; done < test.txt > new.txt
Run Code Online (Sandbox Code Playgroud)