1. Install dos2unix (if not already installed)

On Windows with WSL (Ubuntu example):

sudo apt update
sudo apt install dos2unix

On Linux:

sudo apt install dos2unix

On macOS (with Homebrew):

brew install dos2unix

2. Check the current line endings

You can check if the file uses Windows-style line endings:

cat -v sync-album.sh
  • If you see ^M at the end of lines → it’s Windows (CRLF).

  • If no ^M → it’s already Unix (LF).


3. Convert the file

dos2unix sync-album.sh
  • This will replace all CRLF line endings with Unix-style LF.

  • The conversion happens in-place by default.


4. Make the script executable

chmod +x sync-album.sh

5. Run the script

./sync-album.sh
  • It should now run without errors like /bin/bash^M: bad interpreter.

💡 Tip: If you want to convert multiple files at once:

dos2unix *.sh

Back References: