linux-tutorial/codes/shell/示例脚本/输入和输出/永久重定向.sh
2019-10-10 08:56:31 +08:00

16 lines
364 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# testing STDERR messages
# redirecting all to a file
# 脚本执行期间用exec命令告诉shell重定向某个特定文件描述符
exec 2> test
ls badtest
echo "This is test of redirecting all output"
echo "from a script to another file"
exec 1> test1
echo "This is the end of the script"
echo "but this should go to the testerror file" >&2