简体   繁体   中英

Execution process in pipeline

This code shows nothing(if date.txt does exist):

date > date.txt | cut < date.txt --delimiter ' ' --fields 1

Questions:

  • Why can't we use date.txt if we have redirected stdout in it?
  • Is it like cut takes date.txt as input before it getting written/overwritten? Is the command execution sequence is from left to write in a pipeline or all commands get executed simultaneously and just wait for stdin from stdout of previous pipe command?

[apologies for grammar and terminology mistakes, and

date |tee date.txt | cut --delimiter ' ' --fields 1

works, it is known.

]

在此处输入图片说明

Commands in a pipeline are executed concurrently. So when you write

date > date.txt | cut --delimiter '' --fields 1 < date.txt

cut might try to read from the file before date has written to it, and there's nothing to read. There's no need for a pipeline if you're using a file for communication, just write the commands sequentially.

date > date.txt 
cut --delimiter '' --fields 1 < date.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM