윈도우 개행문자를 리눅스 개행문자로 변경

1 개요[ | ]

sed -i 's/\r$//' 파일명

2 Bash 예시[ | ]

user01@localhost:~$ cat greet.sh 
#!/bin/bash
echo 'hello'
user01@localhost:~$ xxd greet.sh
00000000: 2321 2f62 696e 2f62 6173 680d 0a65 6368  #!/bin/bash..ech
00000010: 6f20 6865 6c6c 6f0d 0a                   o hello..
user01@localhost:~$ bash greet.sh
hello
user01@localhost:~$ ./greet.sh
-bash: ./greet.sh: /bin/bash^M: bad interpreter: No such file or directory
→ 오류 발생
user01@localhost:~$ sed -i 's/\r$//' greet.sh
user01@localhost:~$ ./greet.sh 
hello
→ 조치 후에는 잘 실행된다.
user01@localhost:~$ xxd greet.sh
00000000: 2321 2f62 696e 2f62 6173 680a 6563 686f  #!/bin/bash.echo
00000010: 2068 656c 6c6f 0a                         hello.
→ 0d(\r)가 제거되고 한바이트씩 당겨진 것

3 Python 예시[ | ]

uset01@localhost:~$ cat greet.py 
#!/usr/bin/python3
print('hello')
user01@localhost:~$ python greet.py 
hello
uset01@localhost:~$ ./greet.py 
-bash: ./greet.py: /usr/bin/python3^M: bad interpreter: No such file or directory
user01@localhost:~$ sed -i 's/\r$//' greet.py
user01@localhost:~$ ./greet.py
hello

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}