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
3
  • Did you try \r\n as newline ? Commented Dec 14, 2014 at 10:49
  • I hope that's not your real password here. If it is, change it now. Commented Dec 14, 2014 at 21:09
  • 1
    Gilles. I haven't written real password here Commented Dec 15, 2014 at 3:42

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.