Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Thread Tools Display Modes
  #1   (View Single Post)  
Old 28th June 2010
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,134
Thanked 198 Times in 156 Posts
Default Shell script: echo something to stderr

Is there some native "proper" way to echo to stderr (and *only* stderr) from a shell script? I know I can copy stdout to stderr, but that's not what I want.

As near as I can figure out neither echo nor printf can do this. Am I missing some utility or sh feature?
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #2   (View Single Post)  
Old 28th June 2010
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts

Nope, the programs only output to stdout directly.. at least in the BSD implementations.. without modifying the source a copy of the output will end up there.

One thing you could do is redirect stdout to somewhere temporary (file/pipe), and then copy it to stderr.
Reply With Quote
  #3   (View Single Post)  
Old 28th June 2010
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
Join Date: Apr 2008
Posts: 537
Thanked 49 Times in 43 Posts

echo "I came through stderr" >/dev/stderr
Reply With Quote
  #4   (View Single Post)  
Old 28th June 2010
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 671
Thanked 14 Times in 13 Posts

Originally Posted by Carpetsmoker View Post
I know I can copy stdout to stderr, but that's not what I want.
I think you're saying that
$ echo something >&2
is not what you want. Can you eleaborate on why you don't want it?

Note that if other redirections are around, then maybe grouping
$ { echo something >&2 ; }
or a subshell
$ ( echo something >&2 )
might help.
Reply With Quote
  #5   (View Single Post)  
Old 28th June 2010
vermaden's Avatar
vermaden vermaden is offline
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,048
Thanked 118 Times in 93 Posts


I have always been using echo "..." 1>&2 for that purpose.
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ask for a shell script Simon Programming 5 27th April 2010 01:07 AM
shell script with zenity bsdnewbie999 OpenBSD General 5 24th April 2009 02:37 AM
shell script compare md5 sum bsdnewbie999 Programming 1 11th April 2009 02:20 PM
Shell Script. bsdnewbie999 Programming 21 15th July 2008 07:54 AM
shell script with input c0mrade Programming 5 13th July 2008 04:33 AM

All times are GMT. The time now is 03:19 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick