echo -e behave differently in one case troubleshooting SHELL scripts and the command line

    The development of a co-worker feedback, use echo -e in SHELL script will output the results to a file, behave differently than expected, as follows:
[echo] the man follows

  Colleagues developed the script is called with the script he wrote:

# Vim a.sh 

SH b.sh 

[b.sh contains echo -e operation]

 

  Operating System: ubuntu14.04
  contents of the script [example]:

# CAT test01.sh 
# ! / Bin / bash 

echo -e " AA \ NBB " > / tmp / test.log 

After execution, to get the / tmp / test.log content for
 # SH -x tesh01.sh 
+ echo - AA E \ NBB
 # CAT /tmp/test.log 
- E AA 
bb 
# echo -e "AA \ NBB"> /tmp/test.log 
# CAT /tmp/test.log 
AA 
bb

  You can see the sh execute the script and run the command directly in the shell, you can see the result is not the same. sh executed, although -n also escaped, but the document was more than a -e .
  See here, in fact, the problem has been little prospect of a solution. Then just need to do a little test to test on the line. First, let's compare sh -x execute and direct any different from the command line?
  Some people may have thought, not the same as application execution, command line using the bash bash [my local use, that is, / bin / bash], sh using / bin / sh.
  So why will not the same?
  Look at two documents

# ll /bin/bash 
-rwxr-xr-x 1 root root 1021112 10月 8 2014 /bin/bash*
# ll /bin/sh
lrwxrwxrwx 1 root root 9 11月 7 20:16 /bin/sh -> /bin/dash*

  The reason've seen, / bin / sh soft connection is not linked to the / bin / bash. As for the students who are into this, this not being checked, only need to connect back to soft can be restored to normal.

# ln -sfn /bin/bash /bin/sh

Guess you like

Origin www.cnblogs.com/doctormo/p/12003275.html