grep -q "内容" 文件(绝对路径)
grep -q "set nu" /etc/vimrc
if [ $? -eq 1 ];then 指定内容不存在
if [ $? -eq 0 ];then 指定内容存在
在此以vim默认配置项为例。
grep -q "set nu" /etc/vimrc
if [ $? -eq 1 ];then
echo ‘set nu‘ >> /etc/vimrc
echo ‘colorscheme desert‘ >> /etc/vimrc
echo ‘let &termencoding=&encoding‘ >> /etc/vimrc
echo ‘set fileencodings=utf-8,gbk‘ >> /etc/vimrc
echo ‘set hlsearch‘ >> /etc/vimrc
echo ‘syntax on‘ >> /etc/vimrc
echo ‘set expandtab‘ >> /etc/vimrc
echo ‘set tabstop=4‘ >> /etc/vimrc
echo ‘set shiftwidth=4‘ >> /etc/vimrc
echo ‘set autoindent‘ >> /etc/vimrc
fi
时间: 2024-10-12 15:39:44