bash: 在同一行回显具有延迟的短语

bash: echo phrases with the delays on the same line

作为我 bash 例程的一部分,我需要根据以下逻辑在一行中打印一些消息

echo "Dataset is being rescored !!" | execution of some AWK sctipt | echo "DONE"

我的体会:

# print pharase 1: initiation of the process
echo -n "Dataset is being rescored.. Please wait"; sleep 0.5 
mkdir ${results}
# Apply the following AWK code
while read -r d; do
awk -F, '
# here is some AWK code that operate with target_file.csv and save output to the $results
}'  "${d}_"*/target_file.csv > "${results}/"${d%%_*}".csv"
done < <(find . -maxdepth 1 -type d -name '*_*_*' | awk -F '[_/]' '!seen[]++ {print }')
# print pharase 2 of the result
echo -n " C"; sleep 0.2; echo -n "O"; sleep 0.2; echo -n "M"; sleep 0.2; echo -n "P"; sleep 0.2; echo -n "L"; echo -n "E"; sleep 0.2; echo -n "T"; echo -n "E"; sleep 0.2; echo "D!"

所以我假设短语 2 是在 AWK 脚本执行完成后打印的,并且两个回显都不会影响它的执行。可以吗??

你问的是等待动画吗?好了:)

#Add some color
. ~/SCR/color

#Animation sprites
sprite=(
    "$YLW($RED* $YLW)  ( $RED*$YLW)"
    "$YLW ($RED* $YLW)( $RED*$YLW) "
    "$YLW ( $RED*$YLW)($RED* $YLW) "
    "$YLW( $RED*$YLW)  ($RED* $YLW)"
    "$YLW($RED* $YLW)  ( $RED*$YLW)")

#get the pid of your process
pid=$(...)

#Waiting animation
i=0; while [ -e /proc/$pid ]; do sleep 0.1
    printf "\r${GRN}Please wait... ${sprite[$i]}$DEF"
    ((i++)); [[ $i = ${#sprite[@]} ]] && i=0
done

当您的进程的 pid 存在时,此动画将 运行。

PS:这是 color 脚本的链接