linux-tutorial/codes/shell/输入和输出/永久重定向.sh

16 lines
372 B
Bash
Raw Normal View History

2019-10-29 18:22:19 +08:00
#!/usr/bin/env bash
2019-10-10 08:56:31 +08:00
2019-05-10 11:17:57 +08:00
# testing STDERR messages
# redirecting all to a file
# 脚本执行期间用exec命令告诉shell重定向某个特定文件描述符
2019-10-10 08:56:31 +08:00
exec 2> test
2019-05-10 11:17:57 +08:00
ls badtest
echo "This is test of redirecting all output"
echo "from a script to another file"
2019-10-10 08:56:31 +08:00
exec 1> test1
2019-05-10 11:17:57 +08:00
echo "This is the end of the script"
echo "but this should go to the testerror file" >&2