修改windows檔案的分行符號

來源:互聯網
上載者:User

標籤: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檔案的分行符號

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.