是否有一个很好的备忘单来展示 BASH shell 重定向的多种用途?我很想把这样的东西送给我的学生。我希望看到的一些示例:
cmd > output_file.txt #redirect stdout to output_file.txt
cmd 2> output_file.txt #redirect stderr to output_file.txt
cmd >& outpout_file.txt #redirect both stderr and stdout to output_file.txt
cmd1 | cmd2 #pipe cmd1 stdout to cmd2's stdin
cmd1 2>&1 | cmd2 #pipe cmd1 stdout and stderr to cmd2's stdin
cmd1 | tee result.txt #print cmd1's stdout to screen and also write to result.txt
cmd1 2>&1 | tee result.txt #print stdout,stderr to screen while writing to result.txt
(或者我们可以把它变成一个社区维基并在这里列举这些东西)
谢谢!
SetJmp