Well, fd 0 is associated to stdin and fd 1 to stdout by definition.
If you want to know what files are opened on those fds in a (Bourne-like or csh-like¹) shell, you can do:
lsof -ap "$$" -d 0-1
On Linux or Cygwin, see also:
realpath /dev/stdin /dev/stdout
Though the output is less useful if it's sockets or pipes.
On Linux again, adding -E
to lsof
gives more information for some types of files such as pipes, pseudo-ttys or some sockets as to what's at the other end if any.
Recent versions of util-linux
also have a lsfd
utility (Linux-specific) that can give you some of the same information as lsof
:
lsfd -p "$$" -Q '(fd == 0) or (fd == 1)'
Or
lsfd -p "$$" -Q 'assoc =~ "^[01]$"'
¹ in rc-like shells use $pid
instead of $$
and in fish
: $fish_pid