小编Log*_*Lee的帖子

理解 exec > >(command)

我正在尝试了解exec > >(tee logfile)以下代码中的效果:

#!/bin/bash                                                                                                                 

exec 7>&1           # save stdout for later reset                                                                           

exec > >(tee logfile)          # point stdout to FIFO pointing to tee command?                                              
#+expect any subsequent output to stdout to be sent                                                                         
#+both to stdout and logfile.                                                                                               

# so let's send some output                                                                                                 
echo
echo howdy             # expect these strings to be sent both to terminal and                                               
echo g\'day            #+logfile                                                                                            
echo hello!

# restore stdout                                                                                                            
exec 1>&7
exec 7>&-

#check content of logfile!                                                                                                  
echo ------------ …
Run Code Online (Sandbox Code Playgroud)

bash

4
推荐指数
1
解决办法
152
查看次数

标签 统计

bash ×1