【发布时间】:2020-07-16 10:21:06
【问题描述】:
我在 AIX 上测试了以下内容,它可以工作。
logfile=log.txt
echo "Hello" > "$logfile"
exec 1>>"$logfile"
mv "$logfile" "${logfile}_new"
echo "World"
运行此脚本后,文件log.txt_new 将包含:
Hello
World
我没想到它会起作用,因为我将文件重命名为 stdout 被重定向的位置。为什么会起作用?
如果我 mv/rename 包含日志文件的目录,它也可以工作。
回答: https://unix.stackexchange.com/questions/7707/how-do-open-files-behave-on-linux-systems
【问题讨论】:
-
exec 1>>"$logfile"您在这里重定向命令输出对吗?来自 bash 手册 - 如果未指定命令,则可能会使用重定向来影响当前的 shell 环境。 -
我不知道为什么它重定向到新文件而不是标准输出
-
你的问题更适合Unix & Linux Stack Exchange。
标签: bash unix stdout file-descriptor io-redirection