編碼的世界 / 優質文選 / 女人

echo的換行與不換行


2021年8月18日
-   

       echo默認是有換行的, -n的時候, 是不換行的, 看下man的介紹:
ubuntu@VM-0-13-ubuntu:~$ man echo | grep "-n" -C2
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
ubuntu@VM-0-13-ubuntu:~$

       看下實際例子:
ubuntu@VM-0-13-ubuntu:~$ echo "abc" > a.txt
ubuntu@VM-0-13-ubuntu:~$ xxd a.txt
0000000: 6162 630a abc.
ubuntu@VM-0-13-ubuntu:~$
ubuntu@VM-0-13-ubuntu:~$
ubuntu@VM-0-13-ubuntu:~$
ubuntu@VM-0-13-ubuntu:~$ echo -n "abc" > a.txt
ubuntu@VM-0-13-ubuntu:~$ xxd a.txt
0000000: 6162 63 abc
ubuntu@VM-0-13-ubuntu:~$
      其中, 0a就是換行。
      不多說。

熱門文章