#! /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"