linux-tutorial/codes/shell/示例脚本/输入和输出/创建本地临时文件.sh

23 lines
357 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# creating and using a temp file
tempfile=`mktemp test.XXXXXX`
2019-10-10 08:56:31 +08:00
exec 3> $tempfile
2019-05-10 11:17:57 +08:00
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
2019-10-10 08:56:31 +08:00
rm -f $tempfile 2> /dev/null
2019-05-10 11:17:57 +08:00