linux-tutorial/codes/shell/输入和输出/创建自己的重定向/关闭文件描述符.sh

18 lines
251 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 closing file descriptors
2019-10-10 08:56:31 +08:00
exec 3> test
2019-05-10 11:17:57 +08:00
echo "This is a test line of data" >&3
# closing file descriptor
exec 3>&-
echo "This won't work" >&3
cat test
#覆盖前一个test文件
2019-10-10 08:56:31 +08:00
exec 3> test
2019-05-10 11:17:57 +08:00
echo "This'll be bad" >&3