0

I run Windows 10 bash.exe to run the bash script. I face a wired situation that if I add anything below gradle fatJar in bash it throws an error.

Bash script:(Not working)

#!/usr/bin/env bash
rm -rf build
gradle fatJar
echo 'Success'

' not found in root project 'project_name'. Some candidates are: 'fatJar'.

Bash script:(Working)

#!/usr/bin/env bash
rm -rf build
gradle fatJar

Why I cannot add anything below gradle fatJar? This happens only in Windows 10 bash. In mac, both work fine.

Sai
  • 15,188
  • 20
  • 81
  • 121

1 Answers1

1

I figured it out my self. Hope this answer might help someone.

After a bit of playing around, I found that if I write everything in a single line using && everything worked fine eg:rm -rf build&&gradle fatJar&&echo 'Success' then I realized some wrong with the line breaks. It was adding \r to ever line break.

After a bit of research, I found the cause. It happened because I committed the file in In Mac IntelliJ then later I edited the file in Windows IntelliJ, that last edit changed the Line Separator format of the bash file to CRLF Windows (\r\n) which was adding \r internal to every line breaks.

I changed the line separator to LF UNIX and OS X (\n) and boom everything worked as expected.

To change line separator in IntelliJ follow here and for others here

Sai
  • 15,188
  • 20
  • 81
  • 121