Artificial intelligent assistant

Add in functionality to tail logs while running script? I have a very short script. loading_animation & LOADING_ANIMATION=$! trap "kill -9 $LOADING_ANIMATION" `seq 0 15` task_to_be_performed echo "Script Complete" Script it a little longer than this, but its sums it up nicely. Is there a way to add in functionality so that if i press the key [L] while the script is running (animation being displayed) that the animation will stop, and it will start showing logs until task_to_be_performed is complete? Basically, if i press [L], i want the animation to stop, `tail -f /var/log/messages` to start, and stop when task_to_be_performed is complete, then echoing "Script Complete" and exiting the script entirely. I could not figure it out.

#! /bin/bash
loading_animation &
ani_pid=$!
trap "kill -9 $ani_pid" 0
trap 'done=yes' USR1
output=ani
( task_to_be_performed; kill -USR1 $$) &
while true; do
read -s -n 1 -t 1 input
if [ ani = "$output" ] && [ l = "$input" ]; then
output=log
kill "$ani_pid"
tail -f /var/log/messages &
tail_pid=$!
trap "kill -9 $tail_pid" 0
fi
if [ "$done" = yes ]; then
kill -9 $tail_pid
break
fi
done
echo "Script Complete"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 7baf6623deadcf916ef526be558314bf