redirecionamento de arquivos e arquivos:
cleanup() {
exec {fd}>&-
rm -f "$out"
}
set -e
set -o noclobber
# with noclobber, redirection will fail if output file exists
exec {fd}>"$out" || exit 3
trap "cleanup; exit 4" INT TERM ERR EXIT
# write to already opened file
dd if=/dev/zero of=/dev/fd/$fd bs=256k count=$(( size*4 ))
# alternative to /dev/fd/$fd is redirecting with >&$fd
exec {fd}>&-
Arquivos temporários:
cleanup() {
rm -f "$temp"
}
set -e
temp=$(mktemp "${out}_XXXXXX") || exit 3
trap "cleanup; exit 4" INT TERM ERR EXIT
dd if=/dev/zero of="$temp" bs=256k count=$(( size*4 ))
mv -n "$temp" "$out"