如何从csh脚本重定向stdout和stderr [英] How to redirect stdout and stderr from csh script

查看:133
本文介绍了如何从csh脚本重定向stdout和stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下脚本

install.csh:


#!/bin/csh -f
tar -zxf Python-3.1.1.tgz
cd Python-3.1.1
./configure
make
make install
cd ..
rm -rf Python-3.1.1

预期用途:

./install.csh |& tee install.log

如何更改脚本,以便仍然可以得到install.log和在控制台上输出而不要求用户执行重定向?

How can I change the script so that I still get a install.log and the output on console without asking the user to do the redirecting?

推荐答案

一些简单的解决方案:

解决方案1:
tee您想独立记录的每一行,使用tee的 -a 开关来追加

Solution 1: tee every line you want to log independently, make use of -a switch of tee to append

#!/bin/csh -f    
tar -zxf Python-3.1.1.tgz |& tee -a install.log
cd Python-3.1.1 |& tee -a install.log
./configure |& tee -a install.log
make |& tee -a install.log
make install |& tee -a install.log
cd .. |& tee -a install.log
rm -rf Python-3.1.1 |& tee -a install.log

解决方案2:添加第二个脚本。
例如,将当前的install.csh重命名为install_commands,
,然后添加一个新的install.csh脚本:

Solution 2: Add a second script. For example, rename current install.csh to install_commands, then add a new install.csh script:

#!/bin/csh -f 
/bin/csh install_commands |& tee install.log

这篇关于如何从csh脚本重定向stdout和stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆