如何回应而不被执行

use*_*570 1 bash shell export echo

我试图在/ etc/profile中添加echo语句,但它们会执行.

示例:这是我写的

echo CURRENTYEAR="`/bin/date +%y`" >> /etc/profile 
    echo  CURRENTWEEK="`/bin/date +%V` " >> /etc/profile
    echo VERSION="$CURRENTYEAR"."$CURRENTWEEK" >> /etc/profile
    echo export VERSION >> /etc/profile



      echo export SVN_HOME="https://example.com/svn/road" >> /etc/profile
      echo SVN_BRANCH="$SVN_HOME/branches/qa_weekly/$VERSION" >> /etc/profile
      echo export SVN_TAG="https://example.cpm/svn/road/tags" >> /etc/profile
      echo export SVN_TRUNK="https://example.com/svn/empire/trunk" >> /etc/profile
     export PATH=$PATH:/road >> /etc/profile
     export SVN_BRANCH
Run Code Online (Sandbox Code Playgroud)

结果:我得到了什么

CURRENTYEAR=15
CURRENTWEEK=33
VERSION=.
export VERSION
export SVN_HOME=https://example.com/svn/road
SVN_BRANCH=/branches/qa_weekly/
export SVN_TAG=https://example.com/svn/road/tags
export SVN_TRUNK=https://example.com/svn/road/trunk
Run Code Online (Sandbox Code Playgroud)

我希望它在/ etc/profile中如下所示

CURRENTYEAR=`/bin/date +%y`
CURRENTWEEK=`/bin/date +%V`
VERSION=$CURRENTYEAR"."$CURRENTWEEK
export VERSION

SVN_BRANCH=$SVN_HOME/branches/qa_weekly/$VERSION
SVN_TAG=$SVN_HOME/tags
SVN_TRUNK=$SVN_HOME/trunk
Run Code Online (Sandbox Code Playgroud)

提前致谢.

gle*_*man 5

将您的字符串放在单引号中:

echo 'CURRENTYEAR="`/bin/date +%y`"' >> /etc/profile
#....^.............................^
Run Code Online (Sandbox Code Playgroud)

http://www.gnu.org/software/bash/manual/bashref.html#Single-Quotes

用单引号括起字符可以保留引号中每个字符的字面值.单引号之间可能不会出现单引号,即使前面有反斜杠也是如此.