Script fails with '\r': command not found error message
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Fisheye および Crucible は除く
要約
When running a script in Bamboo it fails and shows "'\r': command not found" and other syntax errors.
環境
Bash Script created/edited on Windows OS.
診断
Looking at the logs of a failed build, the following errors can be seen:
'\r': command not found
syntax error near `]]
syntax error in conditional expression
Illegal characters found in URL
原因
The issue is caused when the script file has a line ending formatting from Windows which is not recognized by bash causing syntax errors. This can happen if the script file being used was, at some point, edited in a Windows machine or had its encoding changed.
ソリューション
To resolve this issue you can use Dos2Unix or a similar tool to convert the script file encoding from Windows to Unix encoding. For example:
dos2unix script.sh