the same bash script in command line doesn't work when run from a file

后端 未结 3 1918
闹比i
闹比i 2021-01-24 06:11

I am trying to lean Bash scripting from cygwin. When i manually type the following lines in command prompt, everything works and I see that the number from 1 to 10 are printed o

相关标签:
3条回答
  • 2021-01-24 06:49

    Another possible solution using unix text editor vi:

    open file in vi edit with vi filename.sh command;

    type in vi :set ff=unix command;

    save file with :wq

    It will save the file with unix line endings.

    0 讨论(0)
  • 2021-01-24 06:54

    I am getting the same error in Notepad++. From this post, I changed Edit --> EOF Convertion, selected Unix/OSX Format, fixed this issue.

    0 讨论(0)
  • 2021-01-24 06:58

    The \r is a hint. Your file probably has CRLF (\r\n) line endings, which the bash interpreter does not handle gracefully. Change your editor settings to use Unix-style (\n) line endings, or run /usr/bin/dos2unix <file> on your file to reset the line endings.

    0 讨论(0)
提交回复
热议问题