How to print a line to STDERR and STDOUT in Bash?

In Bash, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely?

And similarly, how to print the line to STDERR?

asked Jun 5 by dtivl (2,500 points)

1 Answer

In Bash, you can simply use the echo command:

echo "your message here"

or

echo your message here

Examples:

$ echo the message here
the message here
$ echo "the message here"
the message here
$ echo `date`
Fri Apr 7 13:40:20 HKT 2017
$ 

To STDERR:

In Bash:

1>&2 echo "msg to STDERR"

The 1>&2 redirects STDOUT to STDERR.

answered Jun 5 by dtivl (2,500 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...