標籤:linxu try ack color help class mil bin tin
應用情境:
在辦公中,有可能存在,某些命令指令碼使用windows下的文字編輯器進行編寫當放到測試環境的Linux中時,運行報錯
需要使用的軟體:xxd hexdump dos2unix
1、運行windows上編寫好的sh指令碼
[[email protected] ~]# bash test.shtest.sh: line 2: $‘\r‘: command not found‘f: invalid option -- ‘Try ‘df --help‘ for more information.test.sh: line 4: $‘\r‘: command not found‘s: invalid option -- ‘Try ‘ls --help‘ for more information.test.sh: line 6: $‘\r‘: command not found
2、查看sh指令碼
[[email protected] ~]# cat test.sh#!/bin/bashdf -hls -l
3、查看文本的二進位
[[email protected] ~]# xxd test.sh 0000000: 2321 2f62 696e 2f62 6173 680d 0a0d 0a64 #!/bin/bash....d0000010: 6620 2d68 0d0a 0d0a 6c73 202d 6c0d 0a0d f -h....ls -l...0000020: 0a .
4、查看文本的十六進位
[[email protected] ~]# hexdump test.sh0000000 2123 622f 6e69 622f 7361 0d68 0d0a 640a0000010 2066 682d 0a0d 0a0d 736c 2d20 0d6c 0d0a0000020 000a 0000021
5、使用dos2unix修改文本
注意:dos2unix需要安裝後使用,預設系統未安裝
[[email protected] ~]# dos2unix test.shdos2unix: converting file test.sh to Unix format ...
6、查看修改後檔案的二進位和十六進位
# 二進位[[email protected] ~]# xxd test.sh 0000000: 2321 2f62 696e 2f62 6173 680a 0a64 6620 #!/bin/bash..df 0000010: 2d68 0a0a 6c73 202d 6c0a 0a -h..ls -l..# 十六進位0000000 2123 622f 6e69 622f 7361 0a68 640a 20660000010 682d 0a0a 736c 2d20 0a6c 000a 000001b
7、對比
windows:二進位下分行符號號:0d0alinxu:二進位下分行符號號:0a
修改windows檔案的分行符號