Small note "bash: ./a.sh: / bin / bash ^ M: bad interpreter: No such file or directory" solution

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

[taoge@localhost learn_shell]$ ./a.sh   
bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory  
[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

dos2unix a.sh   
bash: dos2unix: command not found  
[taoge@localhost learn_shell]$ busybox dos2unix a.sh   
[taoge@localhost learn_shell]$  
Published 17 original articles · won praise 3 · Views 1071

Guess you like

Origin blog.csdn.net/crisprx/article/details/104134458