sed(学习)
1、清除环境变量
profile=~/.bash_profile
sed -i 's#export LD_LIBRARY_PATH=.*##g' $profile
2、设置环境变量(替换值)
sed -i 's#export LD_LIBRARY_PATH=.*#export LD_LIBRARY_PATH=/opt/testlinux/lib#g' ~/.bash_profile
3、修改配置文件
sdk_dir=/root/test
log_dir=/root/test
#修改cg-casb.properties参数
sed -i 's#SDK_BASE_PATH=.*#SDK_BASE_PATH='$sdk_dir'/testlinux#g' $plugin_dir/cg-casb.properties
sed -i 's#LOG_PATH=.*#LOG_PATH='$log_dir'#g' $plugin_dir/cg-casb.properties
sed -i 's#/opt/casb/logs/plugin#'$log_dir'#g' $plugin_dir/aoelog.xml
4、export设置环境变量
plugin_dir=/root/test
sdk_dir=root/test
if [ -f ~/.bash_profile ];then
check_path=`cat ~/.bash_profile | grep PLUGIN_PATH`
if [ "$check_path" = "" ];then
echo "export PLUGIN_PATH=$plugin_dir" >> ~/.bash_profile
else
if [ -z $PLUGIN_PATH ];then
echo "export PLUGIN_PATH=$plugin_dir" >> ~/.bash_profile
else
sed -i 's#export PLUGIN_PATH=.*#export PLUGIN_PATH='$plugin_dir':'$PLUGIN_PATH'#g' ~/.bash_profile
fi
fiif [ -f ~/.bash_profile ];then
check_path=`cat ~/.bash_profile | grep LD_LIBRARY_PATH`
if [ -z $check_path ];then
echo "export LD_LIBRARY_PATH=$sdk_dir/testlinux/lib" >> ~/.bash_profile
else
if [ -z $LD_LIBRARY_PATH ];then
echo "export LD_LIBRARY_PATH=$sdk_dir/testlinux/lib" >> ~/.bash_profile
else
source ~/.bash_profile
sed -i 's#export LD_LIBRARY_PATH=.*#export LD_LIBRARY_PATH='$sdk_dir'/testlinux/lib:'$LD_LIBRARY_PATH'#g' ~/.bash_profile
fi
fi