我正在处理脚本,我希望隐藏输出,除非出现问题。一切正常,但文件只包含前几行输出,所有内容仍然显示在窗口中。
elif [ $input = "3" ]; then
echo "enter package name"
read package
apt-get build-dep $package
apt-get install $package -y >> /var/log/installlog
exitstatus=$(echo $?)
if [ $exitstatus = "0" ]; then
figlet Installation Successful
else
echo "Failure check /var/log/installlog"
figlet check now?
echo "y or n"
read input2
if [ $input2 = "y" ]; then
cat /var/log/installlog
fi;
fi;
当我检查installlog文件时,我得到了
Reading package lists...
Building dependency tree...
Reading state information...
Reading package lists...
Building dependency tree...
Reading state information...
Reading package lists...
Building dependency tree...
Reading state information...
我尝试过使用tee命令并得到了类似的结果
答案 0 :(得分:0)
请在此行中添加此2>& 1
apt-get install $package -y >> /var/log/installlog 2>&1
添加stderr也是日志文件。