/bin/sh built-in "trap", can't be piped

This will work
Code:
...

fname=trap.txt

trap > "$fname"

echo "Listing $fname contest:"
cat "$fname"

rm "$fname"
 
Anything can be piped but it will run in a subshell environment so that commands like trap will not print what you may expect. (POSIX allows but does not require this.) In our sh, you can do
Code:
traps=$(trap)
and it will return the parent shell environment's traps; this commonly works but is not ubiquitous.
 
Back
Top