bash为终端输出添加颜色

时间:2018-07-11 22:32:57

标签: bash

自动状态会将jobstat变量的状态设为RUNNING或SUCCESS或FAIL。该hack脚本工作正常。直到我想添加一些杂烩。 如果jobstat等于SUCCESS,那么将其以绿色打印到终端上会很酷。其他任何东西,例如“运行中”或“失败”,都将打印为红色。

#!/bin/bash
jobname=$1
hostnam=$(hostname -f | cut -d"." -f2 )
red=$(tput setaf 1)
green=$(tput setaf 2)
reset=$(tput sgr0)
hemisphere="PADC"

while true
do
jobstat=$(autostatus -J $jobname)
choptim=$(date | awk '{print $4}')
    if [[ "$jobstat" == "SUCCESS" ]]; then
     echo "$hemisphere $choptim ${green} ${jobstat} ${reset} $jobname"
     else
     echo "$hemisphere $choptim ${red}${jobstat}${reset} $jobname"
fi
done

但是,当我运行它时,出现此错误

line 14: conditional binary operator expected
line 14: syntax error near `$choptim'
line 14: `echo "$hemisphere $choptim ${green} ${jobstat} ${reset} $jobname"'

0 个答案:

没有答案