Uploaded CentOS shell scripts won't execute until opened & saved in WinSCP editor

Advertisement

Aza
Donor
Joined:
Posts:
2

Uploaded CentOS shell scripts won't execute until opened & saved in WinSCP editor

If I simply upload the script with WinSCP 5.9.5 and set permissions the script will not run in the PuTTY box.

The script will run in the Putty box if i simply open and save the script using the WinSCP editor.

As far as I can tell no ownerships or permissions are altered by the editor open/save.

When this "MyScript.sh" bash script I'm working with fails on CentOS Linux release 7.3.1611 (Core), I get the following error:

-bash: ./MyScript.sh: /bin/bash^M: bad interpreter: No such file or directory

It's odd but not the end of the earth because once you reopen and save using the WinSCP editor the script runs reliably.

Regards,

Aza D. Oberman

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,453
Location:
Prague, Czechia

Re: Uploaded CentOS shell scripts won't execute until opened & saved in WinSCP editor

You most probably use Windows EOLs for a local file. And you then upload it using a binary mode. So Windows EOLs are preserved. *nix shells do not like that.

While, when a file is edited in WinSCP internal editor, text/ascii mode is enforced. So EOLs are converted to *nix style.

Reply with quote

Aza
Donor
Joined:
Posts:
2

Is WinSCP able to convert CR/LF end-of-lines to just LF on uploading?

The thesis that the End Of Line character is CR/LF (0x0D 0x0A)when *nix wants only LF (0x0A) sounds reasonable. I am indeed uploading CentOS shell scripts authored on Windows 10.

Can WinSCP perform the conversion on uploading?

Regards,

Aza

Reply with quote

Advertisement

You can post new topics in this forum