![使用 tee 将用户输入写入文件](https://linux22.com/image/129420/%E4%BD%BF%E7%94%A8%20tee%20%E5%B0%86%E7%94%A8%E6%88%B7%E8%BE%93%E5%85%A5%E5%86%99%E5%85%A5%E6%96%87%E4%BB%B6.png)
我有一个脚本可以指导用户安装我的软件,我想编写一个日志文件,以防出现问题并且用户需要支持。
该脚本如下所示:
while true; do
echo "This script will help you with the installation. Do you wish to proceed?"
echo "(1) Yes"
echo "(2) No"
read proceed
case $proceed in
1 ) break;;
* ) echo "Aborting."; exit 8;;
esac
done
unset proceed
然后我通过使用运行它./install.ksh | tee /var/log/myinstall.log
,一切正常,但用户对问题的输入未记录。当我在命令echo $proceed
后添加时read
,它会写入日志但显示两次,如下所示:
This script will help you with the installation. Do you wish to proceed?
(1) Yes
(2) No
1 #this is the input which is not written to the log
1 # this is the echo which is written to the log
我现在的问题是如何抑制命令的输出read
,或者如何echo
仅将其写入文件而不写入 STDOUT?