4 Commits

Author SHA1 Message Date
684e62e0d8 Beispiele zum Blogpost. 2026-01-17 09:36:55 +01:00
bc827535b9 usage() 2026-01-09 13:42:29 +01:00
1ba9b4ba52 spinner als Wrapper. 2026-01-09 12:59:07 +01:00
88f7a07626 spinner Code. 2026-01-09 09:52:31 +01:00
7 changed files with 126 additions and 0 deletions

6
really-long-command Executable file
View File

@@ -0,0 +1,6 @@
#! /usr/bin/env bash
for i in {1..4}; do
echo "[$$] finished ${i}/4 ticks"
sleep 1
done

46
spinner.sh Executable file
View File

@@ -0,0 +1,46 @@
#! /usr/bin/bash
spinner_pid=
usage() {
local name=${0##*/}
cat <<-EOF
Usage: ${name} {options] <cmd>
Run a command with an animated spinner.
EOF
}
spinner() {
local chars=('\' '|' '/' '-')
local c
while true; do
for c in ${chars[@]}; do
printf "<%s>\r" "${c}"
sleep .2
done
done
}
cleanup() {
echo "done"
if [[ -n ${spinner_pid} ]]; then
kill "${spinner_pid}"
fi
echo "[$$] finished spinner"
}
main() {
trap cleanup EXIT
spinner &
spinner_pid=$!
if (( $# == 0)); then
usage >&2
return 1
fi
"$@"
}
main "$@"

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"