[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: echo redirect additional new line

From: Greg Wooledge
Subject: Re: echo redirect additional new line
Date: Thu, 23 Jul 2015 11:01:46 -0400
User-agent: Mutt/

On Thu, Jul 23, 2015 at 03:41:13PM +0200, Hans Ginzel wrote:
> Hello!
> Consider, please, this small script
> echo 1
> echo 1>"a b"
> echo 2
> echo 2>"c\nd"

Did you intend to write the number "2" to a file, or did you intend to
redirect stderr?

> Why is there the additional new line between 2 and 3 or 3 and 4 
> respectively.

Because you are redirecting stderr instead of stdout.  echo is writing
to stdout, and it has no arguments, so stdout just gets a blank line.
You are redirecting stderr to a file named c\nd (that's four characters,
one of which is a literal backslash), but nothing is being written to
stderr, so the file is 0 bytes long.

I believe you probably wanted:

echo 2 >$'c\nd'

The space after the 2 is extremely significant, and $'...' is how you
create strings (filenames, etc.) with control characters in them.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]