0
0

More than 1 year has passed since last update.

Gitの改行コード

Last updated at Posted at 2023-01-09

スクリプトがWindowsのLinux仮想環境でエラーになる

他の環境では動いているのに……

line 2: $'\r': command not found
line 5: $'\r': command not found
line 35: syntax error near unexpected token `$'do\r''
line 35: `do

改行コードの「\r\n」のうち、「\r」で引っかかっている模様。
「\r\n」はWindowsの改行コードですからね。
Linuxの仮想環境の中では動くはずもありません。

で、なんでこうなってしまっているのかというと。

WindowsでGit pullしたときに、改行コードが変更されてしまうからなんですね。

$ git config --global -l
core.autocrlf=true

上記のようになっていると、Windows環境では自動的に改行コードが変換されてしまうんですね。

git config --global core.autocrlf false

上記のようにして、 autocrlf を無効化する必要があります。

スクリプト自体の改行コードがどのようになっているかは、

cat -e {file}

で確認できます。

行の最後の方に「^M」があったら、Windows改行コードになっています。

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