shell 操作文本内容(修改增加)

#update /usr/etc/servercnfg.xml
 if [ -d "/usr/etc" ];then
    echo "update /usr/etc/servercnfg.xml">>$logfile #插入日志
    sed -i 's!/usr/lib!/home/eduyun/eduyun/webapps/ROOT/WEB-INF/classes/libso/centercontrol/linux/x86!g' /usr/etc/servercnfg.xml #替换文本,用!做分隔符
 
 fi

#update /etc/environment
if [ -d "/etc" ];then
    echo "update /etc/environment">>$logfile
    sed -i 's!/convert/linux!/centercontrol/linux/x86!g' /etc/environment
    if [ ! `grep "RECSVR_APP_PATH" /etc/environment` ];then
        echo 'RECSVR_APP_PATH="/home/eduyun/eduyun/webapps/ROOT/WEB-INF/classes/libso/centercontrol/linux/x86"'>>/etc/environment #判断文本是否存在,不存在则添加文本
    fi
fi

 添加判断还可以写成

if cat /etc/environment | grep /home/eduyun/eduyun/webapps/ROOT/WEB-INF/classes/libso/convert/linux >/dev/null; then
   echo "LD_LIBRARY_PATH is setted!"
else
   echo "LD_LIBRARY_PATH=\"/home/eduyun/eduyun/webapps/ROOT/WEB-INF/classes/libso/convert/linux\"" >> /etc/environment

fi

 

转载于:https://www.cnblogs.com/againn/p/8873431.html

你可能感兴趣的:(shell 操作文本内容(修改增加))