Linux

/dev/stderr vs >&2: a dive into Linux STDIO

I was assisting a bioinformatics workshop for FAANG group at Plant and Animal Genome (PAG) and I ran into an interesting question with an example provided by one of the instructors on the topic of Linux output redirecting. Take a look at this simplified example script print_stderr.sh: #!/usr/bin/bash echo "first line of stderr" > /dev/stderr echo "second line of stderr" > /dev/stderr echo "third line of stderr" > /dev/stderr echo "A line of stdout" Now if we redirect the stderr of this script to a file, instead of all three lines of stderr messages, we only see the last line!