使用 -t FD
能判断文件描述符FD是否与终端相连,因此
if [[ -t 0 ]];then
echo "stdin is a terminal"
else
echo "stdin is not a terminal"
fi
if [[ -t 1 ]];then
echo "stdout is a terminal"
else
echo "stdout is not a terminal"
fi
if [[ -t 2 ]];then
echo "stderr is a terminal"
else
echo "stderr is not a terminal"
fi