请为以下代码提供解决方案。从字符串转换日期和/或时间时,错误转换失败。
#!/bin/bash
set +x
function black(){
echo -e "\x1B[30m $1 \x1B[0m"
if [ ! -z "${2}" ]; then
echo -e "\x1B[30m $($2) \x1B[0m"
fi
}
function red(){
echo -e "\x1B[31m $1 \x1B[0m"
if [ ! -z "${2}" ]; then
echo -e "\x1B[31m $($2) \x1B[0m"
fi
}
function green(){
echo -e "\x1B[32m $1 \x1B[0m"
if [ ! -z "${2}" ]; then
echo -e "\x1B[32m $($2) \x1B[0m"
fi
}
function yellow(){
echo -e "\x1B[33m $1 \x1B[0m"
if [ ! -z "${2}" ]; then
echo -e "\x1B[33m $($2) \x1B[0m"
fi
}
function blue(){
echo -e "\x1B[34m $1 \x1B[0m"
if [ ! -z "${2}" ]; then
echo -e "\x1B[34m $($2) \x1B[0m"
fi
}
function purple(){
echo -e "\x1B[35m $1 \x1B[0m \c"
if [ ! -z "${2}" ]; then
echo -e "\x1B[35m $($2) \x1B[0m"
fi
}
function cyan(){
echo -e "\x1B[36m $1 \x1B[0m"
if [ ! -z "${2}" ]; then
echo -e "\x1B[36m $($2) \x1B[0m"
fi
}
function white(){
echo -e "\x1B[37m $1 \x1B[0m"
if [ ! -z "${2}" ]; then
echo -e "\x1B[33m $($2) \x1B[0m"
fi
}
green "Green: Formating Root partition .."
white "White: Formating Root partition .."
# pass the second parameter, will be treated as command
yellow "color command output,print ls:" "ls"
red "Red: System Free RAM:" "free -m"
cyan "cyan: awesome..........end..................."
echo -e "mix the color $(purple "Purple: this is purple, will print disk usage" "du -h") Now Yellow: $(yellow "hi Yelow") "