Redirect output from a shell script to a file

允我心安 提交于 2019-12-07 18:51:21

问题


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"

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?


回答1:


Like this:

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"


来源:https://stackoverflow.com/questions/15382852/redirect-output-from-a-shell-script-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!