0

So basically I want to write a two line file containing this:

This is line one
This is line two

I can easily do this by doing this command in bash:

echo "This is line one\nThis is line two" > filename

But how would I do this without writing it to stdout.

Any help is appreciated.

5
  • Your slash is going the wrong way, and echo by default wouldn't interpret \n as a new line. Beyond that, what is going to stdout? You mean you want to do it without redirection operators? If so I'd probably use an editor like vi or whatever is your preference Commented Mar 1, 2016 at 22:21
  • Stderr?? Not clear.
    – Jeff Schaller
    Commented Mar 1, 2016 at 22:22
  • Just fixed the slash, didn't realize it. Basically the " > filename" that going to stdout. Commented Mar 1, 2016 at 22:23
  • strange question.... I would creater perl/python/whatever script which saves lines to file. but better try to explain your requirements
    – MAQ
    Commented Mar 1, 2016 at 22:23
  • Stdout is standard output Commented Mar 1, 2016 at 22:23

1 Answer 1

4

In ksh/zsh

print -u3 "This is line one\nThis is line two" 3> filename

would do it using a different file descriptor than 1/stdout if that's what you're asking.

Or you could do:

dd of=filename <<EOF
This is line one
This is line two
EOF

Or:

sed -n 'w filename' <<EOF
This is line one
This is line two
EOF

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .