Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 用破折号检查子字符串的字符串_Bash_Shell_Ubuntu_Dash Shell - Fatal编程技术网

Bash 用破折号检查子字符串的字符串

Bash 用破折号检查子字符串的字符串,bash,shell,ubuntu,dash-shell,Bash,Shell,Ubuntu,Dash Shell,我希望我的motd对我的系统状态有一个很好的概述。 ATM我试图检查执事是否正在运行,并根据其状态对其进行相应的着色 因此,通常您会输入deamon\u name status,它会输出类似deamon\u name running/not running的内容,我会检查not是否包含。成功了 但后来我注意到,当我实际登录并触发MOTD时,我得到了一些错误信息,然后我注意到我需要使用dash,而不是bash或shell。 现在我的比较功能不起作用了 if [[ $Server_name =~ .

我希望我的motd对我的系统状态有一个很好的概述。 ATM我试图检查执事是否正在运行,并根据其状态对其进行相应的着色

因此,通常您会输入
deamon\u name status
,它会输出类似
deamon\u name running/not running
的内容,我会检查
not
是否包含。成功了

但后来我注意到,当我实际登录并触发MOTD时,我得到了一些错误信息,然后我注意到我需要使用
dash
,而不是bash或shell。 现在我的比较功能不起作用了

if [[ $Server_name =~ .*Not.* ]]
    then 
        printf "NOT RUNNING";
    else 
        printf "RUNNING";
fi
这是我的比较函数和检查(稍后我想添加红色/绿色)


$Server\u name
未运行。
运行
我通过比较init脚本中的整个
服务器运行
未运行
字符串解决了这个问题,因为我知道这些消息,并且dash不支持扩展功能,这似乎是合适的

if [ "$ServerName" = "Not running." ]                # I know those messages
    then 
        printf '%b' "\033[31;1mNOT RUNNING\033[0m"   # print NOT RUNNING in red
    else 
        printf '%b' "\033[32;1mRUNNING\033[0m"       # print RUNNING in greend
fi

printf "\n"

我通过比较init脚本中运行的整个
服务器
或未运行的
字符串解决了这个问题,因为我知道这些消息,并且dash不支持扩展功能,所以这似乎是合适的

if [ "$ServerName" = "Not running." ]                # I know those messages
    then 
        printf '%b' "\033[31;1mNOT RUNNING\033[0m"   # print NOT RUNNING in red
    else 
        printf '%b' "\033[32;1mRUNNING\033[0m"       # print RUNNING in greend
fi

printf "\n"

我通过比较init脚本中运行的整个
服务器
或未运行的
字符串解决了这个问题,因为我知道这些消息,并且dash不支持扩展功能,所以这似乎是合适的

if [ "$ServerName" = "Not running." ]                # I know those messages
    then 
        printf '%b' "\033[31;1mNOT RUNNING\033[0m"   # print NOT RUNNING in red
    else 
        printf '%b' "\033[32;1mRUNNING\033[0m"       # print RUNNING in greend
fi

printf "\n"

我通过比较init脚本中运行的整个
服务器
或未运行的
字符串解决了这个问题,因为我知道这些消息,并且dash不支持扩展功能,所以这似乎是合适的

if [ "$ServerName" = "Not running." ]                # I know those messages
    then 
        printf '%b' "\033[31;1mNOT RUNNING\033[0m"   # print NOT RUNNING in red
    else 
        printf '%b' "\033[32;1mRUNNING\033[0m"       # print RUNNING in greend
fi

printf "\n"

dash
中,可以使用case语句进行模式匹配,这也可以在
bash
中使用:

case $Server_name in 
  (*Not*) printf "NOT RUNNING" ;;
  (*)     printf "RUNNING"
esac


dash
中,可以使用case语句进行模式匹配,这也可以在
bash
中使用:

case $Server_name in 
  (*Not*) printf "NOT RUNNING" ;;
  (*)     printf "RUNNING"
esac


dash
中,可以使用case语句进行模式匹配,这也可以在
bash
中使用:

case $Server_name in 
  (*Not*) printf "NOT RUNNING" ;;
  (*)     printf "RUNNING"
esac


dash
中,可以使用case语句进行模式匹配,这也可以在
bash
中使用:

case $Server_name in 
  (*Not*) printf "NOT RUNNING" ;;
  (*)     printf "RUNNING"
esac