2

From windows i am executing a remote shell script using putty plink

cmd>plink.exe -ssh username@hostipd -pw gbG8qs4 /user/alice/listoffiles.sh > C:\log1.txt

Shell script in remote server

#! /bin/bash

echo -e "Hellow\nWorld"

I am getting the output in log1.txt is HelloWorld without any newline. How to get ouput as

Hello
World
  • Did you try \r\n as newline ? – Lorenz Meyer Dec 14 '14 at 10:49
  • I hope that's not your real password here. If it is, change it now. – Gilles Dec 14 '14 at 21:09
  • 1
    Gilles. I haven't written real password here – user188979 Dec 15 '14 at 3:42
1

You are getting a newline in the output. The problem is that this is a Unix newline, which Windows doesn't recognize. Unix encodes newlines as the LF (line feed) character, whereas Windows newlines consist of the two-character sequence CRLF (carriage return, line feed).

To view the output correctly under Windows, use just about anything other than the type command in cmd or the Notepad editor.

If you want to produce output with Windows newlines, you can pipe your script through sed 's/$/\r/'. But note that this output will not work normally under Linux: the extra CR character at the end of the line will be considered part of the line by many applications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.