This post shows how you can save files while retaining their encoding and line endings format. For example, if you’re writing a shell script that will be run on a UNIX operating system, the script is supposed to have line endings as (LF) while Windows’ line endings usually follow (CR)(LF) convention.
So to save a file with its encoding, you need to click on Save As… and then click on the arrow beside the save button as shown below and click on Save with Encoding.
After selecting the file location, VS will show the encoding window where we can select the required encoding. Select the required encoding and click on save. This will save the file with the selected encoding.
Other editors like Notepad++, sublime editor also provide similar options for setting line endings. Personally, I prefer Notepad++. However, best option to prevent line endings to get changed by mistake when moving the script from Windows machine to Unix like System is to use the VI editor within the Unix system itself to avoid the /bin/bash^M: bad interpreter: error message.
Hope this helps!