2016-03-03 96 views
-1

有一个小bash脚本如下有没有什么办法来显示,如果火柴盒

#!/bin/bash 
C="Subsystem  sftp /usr/libexec/openssh/sftp-server #### #### " 
if [ "$D(`grep Subsystem /etc/ssh/sshd_config`)" == "$C" ] 
then 
echo "Entry is proper in sshd_config file" 
else 
echo " Entry present in conf file $D " 
echo "" 
echo -e "it should be \t\t\t$C " 
fi 

但输出类似如下

Entry present in conf file ($D--- is missing) 

it should be  Subsystem  sftp /usr/libexec/openssh/sftp-server #### #### 

的变量有什么办法来显示的$ d如果火柴盒?

+2

您从未设置过$ D? – 123

+1

我想你只是想像''$(grep Subsystem/etc/ssh/sshd_config)''执行grep。我不知道D在做什么 –

+1

什么是“if火柴盒”? – Jens

回答

0

我认为这是你在试图实现的问题。

只需将C更改为您要搜索的字符串即可。

#!/bin/bash 

CONF_FILE="/etc/ssh/sshd_config" # the file to search 
C="Port 22"      # The string you want to find 
RESULTS=$(grep "$C" $CONF_FILE) # The grep result 
LINES_FOUND=$(echo $RESULTS | wc -l) # How many lines contain C in CONF_FILE 

if [ $LINES_FOUND -eq 0 ]; then # File does not contain C 
    echo "Entry not present in conf file $CONF_FILE" 
    echo "" 
    echo -e "it should be \t\t\t$C" 
else       # At least one line matches 
    echo "Entry is proper in $CONF_FILE" 
fi 
+0

@ crick_007 ...感谢您的努力。它工作但使用不同的方式。但是,谢谢你和所有专家的帮助。 – Sandy

相关问题