# A trap fires while a command is half parsed: the parser must resume the # command, not carry on from a freed arena. # # The writer holds the pipe open and feeds `echo "a b` first. When the # shell has started the command it writes its pid, the trap is delivered # mid-token, and the rest arrives after the trap has run. rm -f pid { echo 'trap "echo trapped" USR1' echo 'echo $$ > pid' printf 'echo "a b' while [ ! -s pid ]; do sleep 0.01; done sleep 0.3 kill -USR1 "$(cat pid)" sleep 0.3 printf ' c" x\n' echo 'echo done' } | "$TSH"