重定向从一个shell脚本输出到文件 [英] Redirect output from a shell script to a file

查看:299
本文介绍了重定向从一个shell脚本输出到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我忙着写了一个Capistrano的部署脚本为我们的应用程序之一。其中一个步骤,使用以下命令安装RVM:

I'm busy writing up a Capistrano deployment script for one of our applications. One of the steps installs RVM using the following command:

run "cat ~/rvm-installer.sh | bash -s stable --ruby"

不过,我觉得输出过于冗长,我宁愿要它转储到.log文件。是否有可能重定向别处整个rvm-installer.sh脚本?

However, I feel the output is too verbose, and I rather want to dump it into a .log file. Is it possible to redirect the output for the entire rvm-installer.sh script elsewhere?

推荐答案

这样的:

run "cat ~/rvm-installer.sh | bash -s stable --ruby >out.log"

或者,如果你想重定向的过程中标准错误流,以及:

or, if you want to redirect standard error stream of the process as well:

run "cat ~/rvm-installer.sh | bash -s stable --ruby >out.log 2>err.log"

您也可以重定向一切到同一个文件:

you can also redirect everything to the same file:

run "cat ~/rvm-installer.sh | bash -s stable --ruby >out.log 2>&1"

这篇关于重定向从一个shell脚本输出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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