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

17 lines
240 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# testing closing file descriptors
exec 3>test
echo "This is a test line of data" >&3
# closing file descriptor
exec 3>&-
echo "This won't work" >&3
cat test
#覆盖前一个test文件
exec 3>test
echo "This'll be bad" >&3