[英]Overwrite .bash_profile file in linux
in my .bash_profile file i want to update value of PATH variable. 在我的.bash_profile文件中,我想更新PATH变量的值。 Also, want to add JAVA_PATH and JRE_HOME variables.
另外,要添加JAVA_PATH和JRE_HOME变量。 And, I want to do all this with Shell Script .
而且,我想使用Shell Script来完成所有这一切。
I have no idea about how to do this with commands, so I overwrite the entire file using cat command- 我不知道如何使用命令执行此操作,因此我使用cat命令覆盖了整个文件,
cat >> ~/.bash_profile << _EOF_
#!/bin/bash/
if [ -f ~/.bashrc ]; then
.~/.bashrc
fi
#User specific environment and startup programs
JAVA_PATH=/usr/java/jdk1.6.0_35/bin
PATH=$JAVA_PATH:$PATH:HOME/bin
JRE_HOME=/usr/jdk1.6.0_35
export PATH
unset USERNAME
_EOF_
What would be the impact of doing so with this file? 使用此文件会产生什么影响? How i can easily update value of PATH variable and insert JAVA_PATH and JRE_HOME variables in this file?
我如何轻松更新PATH变量的值并在此文件中插入JAVA_PATH和JRE_HOME变量?
You need to use some text manipulation tool - like sed or awk... 您需要使用一些文本处理工具-诸如sed或awk ...
Here is simple example of how to change the PATH value in your .bash_profile 这是有关如何更改.bash_profile中的PATH值的简单示例
sed 's/^\([[:space:]]*PATH=\)\(.*\)$/\1"\/bin:\/usr\/bin:~\/bin"/' ~/.bash_profile
Notice the escaped special characters ( and / 请注意转义的特殊字符(和/
It you want to overwrite your old file, you need to do it through temporary file like: 如果您想覆盖旧文件,则需要通过临时文件来完成,例如:
sed ... > /tmp/tmpbashprofile$$
mv /tmp/tmpbashprofile$$ ~/.bash_profile
Adding new settings is easy: 添加新设置很容易:
echo "JAVA_PATH=/usr/java/jdk1.6.0_35/bin" >> ~/.bash_profile
Notice the double >> - it appends data to specified file 注意双>>-它将数据追加到指定文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.