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

Author Message
Aza
[View user's profile]

Joined: 2017-06-11
Posts: 2
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
Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26911
Location: Prague, Czechia
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.
Aza
[View user's profile]

Joined: 2017-06-11
Posts: 2
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
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26911
Location: Prague, Czechia
Aza wrote:
Can WinSCP perform the conversion on uploading?

Of course.
See https://winscp.net/eng/docs/transfer_mode
Advertisements

You can post new topics in this forum

Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License