bad interpreter: No such file or directory
Editplus 에서 shell script 를 작성하여, Linux에 올리고 실행을 해보니 정상적인 스크립트 임에도 불구하고 아래와 같은 에러가 계속 발생.
bad interpreter: No such file or directory
문제의 원인은 CR/LF
Windows 기반에서 작성된 text는 줄바꿈을 CR/LF(\r\n)로 처리하는 반면,
Unix/Linux 기반의 text에서는 줄바꿈을 LF(\n)로 처리하면서 발생하는 문제
대부분의 shell script의 첫 문장으로 들어가는 쉘 실행 명령을 ascii문자로 출력해 보면 아래와 같다.
1. Windows에서 작성하여 올린 파일
shell]$ head -1 myscript | od -c | head -1
0000000 # ! / b i n / s h \r \n
-> 이 경우 /bin/sh\r 이라는 명령어를 수행하므로, No such file or directory 라는 에러가 발생
2. Linux에서 작성한 파일
shell]$ head -1 myscript | od -c | head -1
0000000 # ! / b i n / s h \n
-> 정상적으로 스크립트 수행
[참고1] od -c 는 byte를 ascii 문자로 출력하라는 명령
Editplus에서 파일형식을 변경하여 해결.
[참고2]
1) CR(Carriage Return) : 커서를 줄의 맨 처음으로 이동
2) LF(Line Feed) : 커서를 다음 줄로 이동
[참고3]
1) LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, etc.), BeOS, Amiga, RISC OS, and others
2) CR+LF: DEC RT-11 and most other early non-Unix non-IBM OSes, CP/M, MP/M, MS-DOS, OS/2, Microsoft Windows
3) CR: Commodore machines, Apple II family and Mac OS up to version 9
[참고4]
1) http://www.linuxquestions.org/questions/showthread.php?t=213617
2) http://en.wikipedia.org/wiki/Carriage_return
3) http://en.wikipedia.org/wiki/Line_feed
출처 : http://hijh.tistory.com/13
추가 : dos2unix 명령으로 쉽게 해결할 수 있다.