0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WindowsからLinuxにシェルスクリプトを転送したら末尾に^Mが付与され、実行できない場合の対応

Posted at

概要

WindowsからLinuxにシェルスクリプトを転送したら末尾に^Mが付与され、実行できない場合の対応

$ ./test.sh
-bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory

手順

  • viでエラーが発生しているファイルを開き:edit ++ff=unixを実行し、^Mを表示させる

    #!/bin/bash^M
    ^M
    echo testmessage^M
    ^M
    ...
    
  • :%s/^M//gを実行し、^Mを削除する
    ※ ^Mを入力する場合は[ Ctrl+v ][ Ctrl+M ]の順に入力する

    #!/bin/bash
    
    echo testmessage
    
    ...
    
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?