linux寫環境變量對字符轉義

  以前在配置oracle環境換了或者jdk環境,用腳本初始化配置,發現$JAVA_HOME被真實路徑取代,這不操蛋嗎,今天無心間發現echo  -e能夠轉義特殊字符數據庫

得之興業,歲在今朝!bash

  • 對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
相關文章
相關標籤/搜索