![BASH:使用 echo -n 分割代码执行的状态短语](https://linux22.com/image/190460/BASH%EF%BC%9A%E4%BD%BF%E7%94%A8%20echo%20-n%20%E5%88%86%E5%89%B2%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E7%9A%84%E7%8A%B6%E6%80%81%E7%9F%AD%E8%AF%AD.png)
作为 bash 例程的一部分,我在终端中打印一些有关工作流程状态的消息。消息分为两部分(第 1 部分:任务开始,第 2 部分:任务完成状态)
echo -n "Dataset is being processed ! "; execution of some AWK script; echo " Processing has been COMPLETED!"
以下是 bash 中的实现,其中包含 AWK 代码的一部分:
# print pharase 1: initiation of the process
echo -n "Dataset is being rescored.. Please wait"; sleep 0.5
# this is the process: makedir for the result and execute AWK code to process input file
mkdir ${results}
# Apply the following AWK code on the directory contained input file
while read -r d; do
awk -F, '
}' "${d}_"*/target_file.csv > "${results}/"${d%%_*}".csv"
done < <(find . -maxdepth 1 -type d -name '*_*_*' | awk -F '[_/]' '!seen[$2]++ {print $2}')
# print pharase 2: finish of the result, which would appear in the terminal near phrase 1
# this will print "COMPLETED" letter-by-letter with the pause of 0.2 sec between each letter
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!"
在 bash 中执行此脚本时,一切似乎都正常,我没有注意到与两个“echo -n”块之间的代码部分相关的任何问题。使用“echo -n”对状态短语进行这种分割可能会导致 bash 中的例程出现一些错误吗?