在bash脚本中,我使用以下语法将脚本的所有内容打印到文件
我们在我们的Linux RHEL 7.8服务器上运行脚本。
$file
和$sec_file
中。我们在我们的Linux RHEL 7.8服务器上运行脚本。
exec > >(tee -a "$file" >>"$sec_file") 2>&1
当bash脚本完成后,我们将在两个文件中得到每行bash脚本的stdout/stderr内容。
现在我们还想将stdout/stderr打印到控制台而不仅仅是文件中。
我会感激任何建议。
脚本示例:
# more /tmp/script.bash
#!/bin/bash
file=/tmp/file.txt
sec_file=/tmp/sec_file.txt
exec > >(tee -a "$file" >>"$sec_file") 2>&1
echo "hello world , we are very happy to stay here "
运行脚本的示例:
/tmp/script.bash
<-- no output from the script -->
# more /tmp/file.txt
hello world , we are very happy to stay here
# more /tmp/sec_file.txt
hello world , we are very happy to stay here
以下是应该作为期望输出的示例。
/tmp/script.bash
hello world , we are very happy to stay here
和
# more /tmp/file.txt
hello world , we are very happy to stay here
# more /tmp/sec_file.txt
hello world , we are very happy to stay here