mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 08:33:30 +00:00
16 lines
329 B
Bash
16 lines
329 B
Bash
|
|
#!/bin/sh
|
||
|
|
# tmp_demo.sh create and clean a temporary file safely
|
||
|
|
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
tmpfile="$(mktemp -t myscript)"
|
||
|
|
# Arrange cleanup on exit for success or error
|
||
|
|
cleanup() {
|
||
|
|
[ -f "$tmpfile" ] && rm -f "$tmpfile"
|
||
|
|
}
|
||
|
|
trap cleanup EXIT
|
||
|
|
|
||
|
|
echo "Temporary file is $tmpfile"
|
||
|
|
echo "Hello temp" > "$tmpfile"
|
||
|
|
echo "Contents: $(cat "$tmpfile")"
|