一般情况下,每个 Unix/Linux 命令运行时都会打开三个文件:
默认情况下:
command > file
将 stdout 重定向到 filecommand 2 > file
将 stderr 重定向到 filecommand < file
将stdin 重定向到 file。command > file 2>&1
将 stderr 和 stdout合并后重定向到 filecommand > file1 < file2
将 stdout 重定向到 file1,stdin 重定向file2command 2 >> file
将 stderr 追加到 file末尾
如果希望执行某个命令,但又不希望在屏幕上显示输出结果,那么可以将输出重定向到 /dev/null
command > /dev/null 2>&1
屏蔽 stdout 和 stderr
bash#! /bin/bash
if command -v git >/dev/null 2>&1; then
echo 'exists git'
else
echo 'no exists git'
fi
bash#! /bin/bash
if type git >/dev/null 2>&1; then
echo 'exists git'
else
echo 'no exists git'
fi
bash#! /bin/bash
if hash git 2>/dev/null; then
echo 'exists git'
else
echo 'no exists git'
fi
https://www.jianshu.com/p/fbffa5cc49e1 http://c.biancheng.net/cpp/view/2738.html
本文作者:mereith
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!