File: example.ia_mktemp

package info (click to toggle)
shellia 5.7.6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 728 kB
  • sloc: sh: 7,087; makefile: 34
file content (31 lines) | stat: -rwxr-xr-x 975 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# vim: set filetype=sh :
#        file: example.ia_mktemp
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
#     license: GNU General Public License, version 3
# description: example using function ia_mktemp and ia_rmtemp
#    see also: test.ia_mktemp
set -e
set -u

. ./ia.check

sub()
{
  ia_mktemp file
  [ -f $file ] && echo "sub: file exists: $file" >&2 || echo "sub: file does not exist: $file" >&2
  echo "$file"
  #ia_get_exit_trap t; ia_dev_dbg "sub: t=<$t>"
}

sub >/dev/null
# file should exist
[ -f $file ] && echo "main: file exists: $file" >&2 || echo "main: file does not exist: $file" >&2
# delete file manual
ia_rmtemp $file
# file should be deleted now
[ -f $file ] && echo "main: file exists: $file" >&2 || echo "main: file does not exist: $file" >&2

file="$(sub)"
# file should be deleted by trap, after leaving subshell
[ -f $file ] && echo "main: file exists: $file" >&2 || echo "main: file does not exist: $file" >&2