What is `/dev/null`, `/dev/stdin`, `/dev/fd/N` and `/dev/tcp/host/port`?
IntermediateConceptArguments, I/O, here-docs, process substitution and subshells
Answer
/dev/nulldiscards writes and returns EOF on reads./dev/stdin,/dev/stdout,/dev/stderr,/dev/fd/Nrefer to the process's file descriptors (handy for tools that only accept a filename)./dev/tcp/HOST/PORTand/dev/udp/HOST/PORTare Bash pseudo-files that open a socket, useful whenncis not installed:
if timeout 3 bash -c '</dev/tcp/db.internal/5432' 2>/dev/null; then
echo "postgres port open"
fi
/dev/tcp is a Bash feature (it may be disabled at compile time on some distros), not a real device.
More on Arguments, I/O, here-docs, process substitution and subshells
How does `getopts` work? Show a complete example.IntermediateWhat is the difference between `getopts` and `getopt`?AdvancedExplain file descriptors 0, 1 and 2 and the main redirection operators.BeginnerWhy is `cmd 2>&1 > file` different from `cmd > file 2>&1`?AdvancedWhat is a here-document, and what is the difference between `<<EOF`, `<<'EOF'` and `<<-EOF`?BeginnerWhat is a here-string (`<<<`)?Intermediate