I do a lot of services in .Net core and .Net 5 that is meant to run on Linux servers, and sometimes I need to include shell script (.sh files) with those services to be called from the commandline.
This often fails miserably when running those scripts, as the shell throws strange errors when running, as it has a hard time reading the code!
This is due to the encoding of the files in Windows being UTF-8 W/BOM!
But you can change this to UTF-8 Without Signature, and this will solve the issues.
How to create a file and change the encoding.
If you already created a file, you can resave it as UTF-8 Without Signature like this.
- Open the file in the editor. (Mine is called MyScript.sh
- Go to File –> Save MyScript.sh AS…
3. Now we want to keep everything as is, but instead of clicking the save button, we use the little arrow on the button which gives us an option to Save with Encoding..
4. You will be asked if you want to replace it, and you can click yes
5. As you can see the encoding selected is With signature, which is what Linux is complaining about. So you can go ahead and scroll to the bottom and find “Unicode (UTF-8 without signature) – Codepage 65001”
6. Click OK to save the file and you are good to go!
Now when saving this specific file in the future it will remember the setting, so you only have to do this once per file.