Init scripts failing with unexpected end of file error

Remove the special characters from the init script.

Written by jeremy.ramirez

Last published at: December 20th, 2024

Problem

When you create init scripts using Windows Notepad or similar Integrated Development Environments (IDEs) and directly upload these files, you encounter the following error. 

 

/<path-to-init-script>/<init-script.sh>: line n: syntax error: unexpected end of file

 

Cause

Windows Notepad and similar editors insert special characters like carriage returns (\r), which are not visible within the script but are incompatible with Linux-based environments. Since Databricks clusters operate on a Linux OS, these characters cause the script to fail. 

 

Solution

Follow the steps in the Databricks KB article Init script stored on a volume fails to execute on cluster start