LoginSignup
3
0

More than 1 year has passed since last update.

シェルスクリプトを実行しようとしたら「syntax error: unexpected end of file」が出た場合

Posted at

共同開発をしているソフトウェアのインストールスクリプトを実行したところ,以下のエラーが出た

$'\r': command not found
syntax error: unexpected end of file

調べてみたところ,Windowsでスクリプトの編集を行った方がいて,改行コードが異なったファイルが混じってしまっていたようだった.
これを一括で修正を実行した.
シェルスクリプトがいくつかのディレクトリに配置されているため,サブディレクトリの中も.shファイルを探索して変換するコマンドを忘備録的に記載しておく.

find . -type f -name "*.sh" -print0 | xargs -0 nkf --overwrite -w -Lu
  • 「.」:探索の開始点はカレントディレクトリ
  • 「"*.sh"」:シェルスクリプトファイルを指定
  • 「-Lu」:改行コードをUNIX系のものにする
3
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
3
0