ubantu run .sh script problems

Some people like to use vim to write linux shell script, however, some people like to use some handy editor (such as the famous Notepad ++) written under Windows, and then copy the files to linux, it results in a script execution .sh when a problem arises:

[plain] view plain copy

  1. [taoge@localhost learn_shell]$ ./a.sh   
  2. bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory  
  3. [taoge@localhost learn_shell]$   

      What causes it, we have reason to suspect that the problem is a file format? We enter with vim a.sh a.sh this file, and then in the bottom of the model, execute: set ff look and found fileformat = dos, look, it really is a file format issue, then how to solve it?

     Method a: vim a.sh after entering a.sh, in the foot mode, execute: set fileformat performed after = unix: x or: wq save the changes. Then you can execute ./a.sh run script. (I personally tried, ok for)

     Method two: direct execution sed -i "s / \ r //" a.sh to convert, and then you can perform ./a.sh run script. (I personally tried, ok for)

     Method three: direct execution dos2unix a.sh to convert, and then you can perform ./a.sh run script. (Dos2unix ./a.sh failure to perform on my linux, but do not give up, ah, add busybox on it), as follows:

[plain] view plain copy

  1. dos2unix a.sh   
  2. bash: dos2unix: command not found  
  3. [taoge@localhost learn_shell]$ busybox dos2unix a.sh   
  4. [taoge@localhost learn_shell]$  

Guess you like

Origin www.cnblogs.com/TJGKK/p/11411962.html