相关疑难解决方法(0)

bash 管道 vs 此处字符串

我认为这些命令在 bash 中是等效的,但它们产生不同的输出。你能帮我理解为什么吗?

$ echo "SEBA" | wc
      1       1       5
Run Code Online (Sandbox Code Playgroud)
$ wc <<< "SEBA"
1 1 5
Run Code Online (Sandbox Code Playgroud)

继续运行

  • Ubuntu 20.04.2 LTS
  • GNU bash,版本 5.0.17(1)-release (x86_64-pc-linux-gnu)
  • wc (GNU coreutils) 8.30

这里有一些测试:

$ echo "SEBA" | wc | hexdump 
0000000 2020 2020 2020 2031 2020 2020 2020 2031
0000010 2020 2020 2020 0a35                    
0000018
Run Code Online (Sandbox Code Playgroud)
$ wc <<< "SEBA" | hexdump 
0000000 2031 2031 0a35                         
0000006
Run Code Online (Sandbox Code Playgroud)
$ echo "SEBA" | hexdump 
0000000 4553 4142 000a                         
0000005
Run Code Online (Sandbox Code Playgroud)
$ hexdump <<< "SEBA"
0000000 4553 …
Run Code Online (Sandbox Code Playgroud)

bash pipe

2
推荐指数
1
解决办法
59
查看次数

标签 统计

bash ×1

pipe ×1