I'm trying to learn how to use trap in bash. I'm on ubuntu ohmyzsh.
This is a test case, but I would wish to call a function with the params that was passed in when the function was called to the function that is called on exit. Right now it does not even call the function in trap.
xtest() {
trap 'xecho' EXIT
echo 'start'
while :; do echo 'Hit CTRL+C'; sleep 1; done
}
xecho() {
echo "done $1"
}
I just get
$ xtest foo
start
Hit CTRL+C
Hit CTRL+C
^C%
I've noticed this answer to use SIGINT and to use exit in the function that gets called by trap, but then it closes the terminal, otherwise it doesn't stop the loop. So still confused and it doesn't help me with my example of getting the param foo echoed out on break.