bash脚本中未终止的地址正则表达式错误

bash脚本中未终止的地址正则表达式错误,bash,redhat,Bash,Redhat,我想使用bash脚本编辑sshd_config文件。然而,我不断地得到一个错误。我将非常感谢您给予的任何帮助 这是我的剧本: if ! grep "IgnoreRhosts" "/etc/ssh/sshd_config"; then sed -i /etc/ssh/sshd_config -e '/# Don't read the user's ~/.rhosts and ~/.shosts files/a IgnoreRhosts yes' printf "\e[32m IGN

我想使用bash脚本编辑sshd_config文件。然而,我不断地得到一个错误。我将非常感谢您给予的任何帮助

这是我的剧本:

if ! grep "IgnoreRhosts" "/etc/ssh/sshd_config"; then
    sed -i /etc/ssh/sshd_config -e '/# Don't read the user's ~/.rhosts and ~/.shosts files/a IgnoreRhosts yes'
    printf "\e[32m IGNORERHOSTS YES ADDED\e[0m\n"
elif grep "#IgnoreRhosts yes" "/etc/ssh/sshd_config"; then
    sed -i 's/^#IgnoreRhosts yes/IgnoreRhosts yes/' /etc/ssh/sshd_config
    printf "\e[32mSUCCESSFULLY CHANGED\e[0m\n"
else
    printf "\e[32mNO CHANGES NEEDED\e[0m\n"
fi
这是我得到的错误:

sed: -e expression #1, char 7: unterminated address regex
脚本错误行:

 sed -i /etc/ssh/sshd_config -e '/# Don't read the user's ~/.rhosts and ~/.shosts files/a IgnoreRhosts yes'
这一条应该有效:

sed -i /etc/ssh/sshd_config -e "\|# Don't read the user's ~/.rhosts and ~/.shosts files|a IgnoreRhosts yes"
说明: 在这个脚本中,我使用
|
作为分隔符,以使其更具可读性。此分隔符由第一个
\
定义(更多信息)


然后,我使用双引号而不是单引号来避免在单词
用户的

'/#不…
中转义撇号,第二个引号关闭第一个引号;您需要转义内部引号(
\'
),还需要转义regexp中的
/
字符。请尝试
sed-i-e'/\35; Don'\''t读取用户的~\/.rhosts和~\/.shosts文件/a IgnoreRhosts yes/'/etc/ssh/sshd\u config