Beispiele zum Blogpost.

This commit is contained in:
2026-01-17 09:36:55 +01:00
parent bc827535b9
commit 684e62e0d8
5 changed files with 74 additions and 0 deletions

10
teil25/notrap Executable file
View File

@@ -0,0 +1,10 @@
#! /usr/bin/bash
touch /tmp/testfile
sleep 10
echo "Ende der Arbeit"
rm /tmp/testfile

23
teil25/on-exit.sh Executable file
View File

@@ -0,0 +1,23 @@
#! /usr/bin/bash
on_exit() {
echo "Programmende signalisiert."
}
on_debug() {
echo "debug handler"
echo "[DEBUG] counter=${counter}"
}
trap on_exit exit
trap on_debug debug
sleep 10
#counter=0
#while true; do
# let counter++
# echo "running..."
#done

15
teil25/sighup.sh Executable file
View File

@@ -0,0 +1,15 @@
#! /usr/bin/bash
on_hup() {
echo "hup handler"
}
trap on_info SIGHUP
my_pid=$!
echo "${my_pid}"
while true; do
sleep 1
done

15
teil25/trap Executable file
View File

@@ -0,0 +1,15 @@
#! /usr/bin/bash
cleanup() {
echo "Programmende signalisiert."
rm /tmp/testfile
}
trap cleanup exit
touch /tmp/testfile
trap - exit
sleep 10
echo "Ende der Arbeit"

11
teil25/trap2 Executable file
View File

@@ -0,0 +1,11 @@
#! /usr/bin/bash
trap "echo vorbei" SIGINT
touch /tmp/testfile
sleep 10
echo "Ende der Arbeit"