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


#update /usr/etc/servercnfg.xml
 if [ -d "/usr/etc" ];then
    echo "update /usr/etc/servercnfg.xml">>$logfile #插入日志
    sed -i 's!<cc1path>/usr/lib</cc1path>!<cc1path>/home/eduyun/eduyun/webapps/ROOT/WEB-INF/classes/libso/centercontrol/linux/x86</cc1path>!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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM