Spinner 动画和 echo 命令

Spinner Animation and echo command

这是我的 bash 文件的一部分。我需要的输出是:

[-] KatworX© Tech 版权所有。由 Arjun Singh Kathait 开发并由 ☆Stack Overflow 社区调试☆

我希望微调器动画在显示 echo 命令时继续旋转 5 秒。社区可以提供帮助吗???

spinner()
    {
        local pid=$!
        local delay=0.75
        local spinstr='|/-\'
        while [ "$(ps a | awk '{print }' | grep $pid)" ]; do
            local temp=${spinstr#?}
            printf " [%c]  " "$spinstr"
            local spinstr=$temp${spinstr%"$temp"}
            sleep $delay
            printf "\b\b\b\b\b\b"
        done
    }

         sleep 5 & spinner | echo -e "\nCopyright of KatworX© Tech. Developed by Arjun Singh Kathait and Debugged by the ☆Stack Overflow Community☆"

从评论继续。为了避免在每次迭代时调用 psawkgrep,您需要将 PID 作为参数传递给自旋函数。 (你也可以传递一个字符串来显示和默认为你的字符串)。我会做类似的事情:

#!/bin/bash

## spinner takes the pid of the process as the first argument and
#  string to display as second argument (default provided) and spins
#  until the process completes.
spinner() {
    local PROC=""
    local str="${2:-'Copyright of KatworX© Tech. Developed by Arjun Singh Kathait and Debugged by the ☆Stack Overflow Community☆'}"
    local delay="0.1"
    tput civis  # hide cursor
    printf "3[1;34m"
    while [ -d /proc/$PROC ]; do
        printf '3[s3[u[ / ] %s3[u' "$str"; sleep "$delay"
        printf '3[s3[u[ — ] %s3[u' "$str"; sleep "$delay"
        printf '3[s3[u[ \ ] %s3[u' "$str"; sleep "$delay"
        printf '3[s3[u[ | ] %s3[u' "$str"; sleep "$delay"
    done
    printf '3[s3[u%*s3[u3[0m' $((${#str}+6)) " "  # return to normal
    tput cnorm  # restore cursor
    return 0
}

## simple example with sleep
sleep 5 &

spinner $!

(显示为蓝色 -- 但您可以删除第一个 printf 以移除颜色)