linux写环境变量对字符转义
之前在配置oracle环境换了或者jdk环境,用脚本初始化配置,发现$JAVA_HOME被真实路径取代,这不操蛋吗,今天无意间发现echo -e可以转义特殊字符
得之兴业,岁在今朝!
-
对oracle账户下oaclle单实例数据库变量的设置
#!/bin/bash
echo export ORACLE_BASE=/u01/app/oracle >>.bash_profile
echo -e "export ORACLE_HOME=\$ORACLE_BASE/product/12c" >>.bash_profile //echo -e 对特殊字符转义 \$ 写入到文件 $
echo export ORACLE_SID=oracle12c >>.bash_profile
echo -e "PATH=\$PATH:$HOME/bin:\$ORACLE_HOME/bin:\$ORACLE_HOME/lib:\$ORACLE_HOME/lib64" >>.bash_profile
echo -e "LD_LIBRARY_PATH=\$ORACLE_HOME/bin:/usr/bin" >>.bash_profile
echo export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK" >>.bash_profile
source ~/.bash_profile //刷新用户环境变量
-
官方对echo解释
ECHO(1) User Commands ECHO(1)
NAME
echo - display a line of text
SYNOPSIS
echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION
DESCRIPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline //不换行
-e enable interpretation of backslash escapes //允许转义字符
-
Linux直接转义特殊字符
#!/bin/bash #desc init jdk env cat >> ~/.bash_profile<<EOF export ABC=/tmp export abc=\$ABC/123 EOF //结果 [root@lab-120 ~]# cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs export PATH=$PATH:$HOME/bin export ABC=/tmp export abc=$ABC/123