����Linux�Ż�
Linux����

bash shell:�ű����޸�profile�ļ�����LD_LIBRARY_PATH��ʾ��

����ʱ��:2016-11-09 09:36:06��Դ:blog.csdn.net/10km����:10km
�����ǵ�һ����Ŀ��ɣ���Ҫ��Linux�°�װ����Ҫд��װ�ű�����ʱ����Ҫ�޸�profile�ļ��޸Ļ�����������ʱ��Ҫ�õ�sed�༭����sed�༭�����������༭��(stream editor),����ͨ����ʽ�ļ��༭���෴���ڽ���ʽ�༭����(����vim)��������ü�������������ʽ�ز��롢ɾ�����滻�����е��ı������༭������ڱ༭����������֮ǰ����Ԥ���ṩ��һ��������༭��������
�������ǿ�������sed�༭���ڰ�װ�ű�ʵ�ֶ�profile�ļ����޸ġ�
 
����������һ��ʵ��Ӧ�õ�������˵����
���Ѿ���һ����CASSDK����Ŀ�������Ŀû�п�ִ���ļ���ֻ��һ�鶯̬���ļ��ṩ���Ӧ�ó������(����Java)����ҪΪ��дһ����װ�ű����ű��������ǽ��ڽ��ļ����Ƶ�ָ����װĿ¼��Ȼ���޸�LD_LIBRARY_PATH����������װĿ¼���뵽LD_LIBRARY_PATH������,�Ա�java�������JNI����ء�
���⻹Ҫдһ��ж�ؽű�����ɾ����װĿ¼��ͬʱ��profile�е�LD_LIBRARY_PATH����Ҳͬ���޸ġ�
 
������ԭʼ��profile�ű�Ƭ�Σ�
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export LD_LIBRARY_PATH=/usr/local/face/lib:$LD_LIBRARY_PATH
 
�����ǰ�װ�ű�Ƭ�Σ����ļ�ĩβ����export���INSTALL.sh��
# ���尲װĿ¼λ�õı���
cassdk_path=/home/gdface/cassdk
# ����Ҫ��profile����������
new_export="export LD_LIBRARY_PATH=$cassdk_path:\$LD_LIBRARY_PATH"
# ����������תΪ�������ʽ
reg_str="^\s*export\s*LD_LIBRARY_PATH=$cassdk_path:\$LD_LIBRARY_PATH"
# ����grep����profile�Ƿ��Ѿ�����ָ������䣬����У���Ͳ���Ҫ��������
if grep -q $reg_str /etc/profile
then
echo $cassdk_path exists in LD_LIBRARY_PATH,skip
else    
# export LD_LIBRARY_PATH=$cassdk_path:\$LD_LIBRARY_PATH
echo defined LD_LIBRARY_PATH variable
# ֱ����profileĩβ�������� 
echo $new_export >> /etc/profile
fi
# ��ʾexport���
grep $reg_str /etc/profile
 
INSTALL.shִ�к�
profile�ļ���ĩβ����һ��export LD_LIBRARY_PATH=/home/gdface/cassdk:$LD_LIBRARY_PATH
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export LD_LIBRARY_PATH=/home/hadoop/workspace/cassdk/release/cassdk_linux_x86_64/bin:/usr/local/face/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/gdface/cassdk:$LD_LIBRARY_PATH
 
������ж�ؽű�(UNINSTALL.sh)Ƭ�Σ���sed�޸�profile�ļ���ɾ����װ�ű����ӵ�export��䣺
# ���尲װĿ¼λ�õı���
cassdk_path=/home/gdface/cassdk
# ��cassdk_path�ַ����е������ַ�/��.�滻Ϊ\/��\. ,���ʺ��������ʽҪ��
reg_path=`echo $cassdk_path|sed -r 's/([\/\.])/\\\\\1/g'`
echo delete the line if exist:
echo \"export LD_LIBRARY_PATH=$cassdk_path:\\\$LD_LIBRARY_PATH\"
# ����sedɾ���������ʽָ������
sed -i_bak -r "/^\s*export\s*LD_LIBRARY_PATH=$reg_path:\$LD_LIBRARY_PATH/d" /etc/profile 
# �������ʽ��/d��ָɾ�� 
# -i_bak������ָ���޸�profile֮ǰ����һ����Ϊprofile_bak�ı��ݡ�
 
UNINSTALL.shִ�к�ű���export LD_LIBRARY_PATH=/home/gdface/cassdk:$LD_LIBRARY_PATH���д��뱻�Զ�ɾ����
������޸�����/etc/profile��ʾ���ģ�������Ҫ��rootȨ��ִ�У���Ȼ��Ҳ������ͬ���İ취�޸�~/.bash_profile��
 
�������ø��µ�ַ��//m.ajphoenix.com/linux/25842.html