我有一个脚本可以指导用户安装我的软件,我想写一个日志文件以防万一发生不好的事情并且用户需要支持。
脚本如下所示:
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
然后我通过 using 运行它./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?
您应该改用
script
它,它正是为此目的而设计的:它将记录输入
read
以及任何输出。