创建临时文件.sh Shell 脚本

Shell 片段 · codes/shell/文件操作/创建临时文件.sh · 19 行

源码

#!/usr/bin/env bash

tempFile=`mktemp test.XXXXXX`

exec 3> ${tempFile}

echo "This script writes to temp file ${tempFile}"
echo "This is the first line" >&3
echo "This is the second line" >&3
echo "This is the last line" >&3

exec 3>&-

echo "Done creating temp file. The contents are:"
cat ${tempFile}

rm -f ${tempFile} 2> /dev/null

查看上游源码 ↗

内容与示例整理自 dunwu/linux-tutorial,遵循 CC BY-SA 4.0;本站保留原作者署名与许可,命令仅供学习,执行前请核对目标环境。