Writing to standard error?

Writing to standard error?

Post by Eric J. Ostrande » Thu, 04 Apr 1996 04:00:00



Dear comp.unix.shell readers,

  The question is a straight forward one.  How does
one send to standard error from a shell script?
All the echo's and print's and such go to standard
out.
  What I would like is for my own shell script warning
messages to be sent to standard error and not JUST echo'ed
to the user.
  Thank you.

                           Eric J. Ostrander

                           Senior Scientific Programmer
                           Johns Hopkins University

 
 
 

Writing to standard error?

Post by Peter Turnbul » Fri, 05 Apr 1996 04:00:00



> Dear comp.unix.shell readers,

>   The question is a straight forward one.  How does
> one send to standard error from a shell script?
> All the echo's and print's and such go to standard
> out.
>   What I would like is for my own shell script warning
> messages to be sent to standard error and not JUST echo'ed
> to the user.
>   Thank you.

>                            Eric J. Ostrander

>                            Senior Scientific Programmer
>                            Johns Hopkins University

If you are using non-csh (ie: ksh,sh,bash,zsh etc):

echo "WARNING" >&2

If you want to redirect stderr from all commands to a file, use:

exec 2>filename
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Department of Employment, Education, Training and Youth Affairs
------------------------------------------------------------------------
Lobbying the government to increase the height on Mt Kosiuskco by
another 1000 metres so that it will have a permanent snow cover.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

 
 
 

Writing to standard error?

Post by Ray A. Jon » Fri, 05 Apr 1996 04:00:00



: Dear comp.unix.shell readers,

:   The question is a straight forward one.  How does
: one send to standard error from a shell script?
: All the echo's and print's and such go to standard
: out.
:   What I would like is for my own shell script warning
: messages to be sent to standard error and not JUST echo'ed
: to the user.
:   Thank you.

Bourne shell:
echo "This is an error" 2> error.file
Standard in is file descriptor 0
Standard out is file descriptor 1
Standard error is file descriptor 2, thus the 2> above

Or, you can set up the script to trace all functions, including errors and
all step as they occure, with shell substitutions with:

        exec 2> /tmp/sh.err
        set -x

A the begining of the shell script.
--

URL: http://www.celestial.com         One Mercer Plaza, Suite S100
                                      Mercer Island, WA 98040; (206) 236-1676
Manufacturer of InterRack (Internet-in-a-Rack), a full turn-key
system, including all the hardware, software, installation, setup, training
and support for businesses and Internet Service Providers

 
 
 

Writing to standard error?

Post by David and Rachel Weintra » Mon, 08 Apr 1996 05:00:00




> Dear comp.unix.shell readers,

>   The question is a straight forward one.  How does
> one send to standard error from a shell script?
> All the echo's and print's and such go to standard
> out.
>   What I would like is for my own shell script warning
> messages to be sent to standard error and not JUST echo'ed
> to the user.
>   Thank you.

What shell are you using? If you're using ksh, then it's simply:

print -u2 "<your error message here>"

The "-u2" tells the print statement to put the message onto STDERR.

--
David Weintraub                    _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
System Configuration Management   _/                                      _/
Dow Jones/Telerate - NSG         _/    I AM THE GREAT AND POWERFUL OZ*   _/


                           *Pay no attention to the man behind the curtains

 
 
 

Writing to standard error?

Post by Mikel Douce » Tue, 09 Apr 1996 04:00:00



>   The question is a straight forward one.  How does
> one send to standard error from a shell script?
> All the echo's and print's and such go to standard
> out.
>   What I would like is for my own shell script warning
> messages to be sent to standard error and not JUST echo'ed
> to the user.
>   Thank you.

In bourne (/bin/sh):

  echo "seterr test string" >$2

-------------------------------------------------------------------------------
| Mikel Doucet, eng                  |   ATS Aerospace Inc.                   |

| Tel : +1 (514) 441-6744 (ext 291)  |   St-Bruno, Quebec (Canada)            |
| Fax : +1 (514) 441-6789            |   J3V 6B8                              |
-------------------------------------------------------------------------------

 
 
 

Writing to standard error?

Post by Bill Marc » Sat, 13 Apr 1996 04:00:00




Quote:>In bourne (/bin/sh):

>  echo "seterr test string" >$2

You mean >&2

--

From the future home of the 270 Foot Jesus

 
 
 

1. Writing to standard error in shell and awk?

Hi folks.

I am writing some involved shell scripts using a lot of awk in order to
produce ASCII files for loading into a database.  Obviously I want my
stdout to be the ASCII file.  However, I also want to be able to write
"log" messages to stderr. So I have a 2-part question (hence the cross-
post) though I obviously have the answer to one question
:
a. How can I use the "echo" command to write a message to stderr? Here
   is my little test shell-script:
   $ cat test_out
   echo This should go to standard output
   echo 1>&2 This should go to stderr

   Indeed, when I run this command:
   $ test_out >x.x 2>x.y
   I get the appropriate line in the corresponding line.

b. How do I write to stderr in awk?  Since the awk script is generating
   most of my output, I want to be able to write logging and progress
   messages to stderr.  For the moment I have used print >"/dev/tty" but
   then this cannot be redirected from the command line.

Ideas?

Thanks.
--
    -- Jake (In pursuit of undomesticated aquatic avians)

+-----------------------------------------------------------+
|    Impeccable Logic: A thought process which successfully |
|                      resists chicken bites                |
+-----------------------------------------------------------+

2. backup filesystem with mksysb

3. redirecting standard output and standard error

4. Fatal signal 11 when Compiling Kernel - Solved (for me)

5. standard out and standard error

6. DVIPS doesn't run with 3.1.76 !

7. differentiate between standard output and standard error?

8. HylaFax 4.1 problem (not answering)

9. standard out and standard error questions

10. capturing standard error info but not standard out

11. How to redirect standard error to standard output (in csh)?

12. LCSDNYR 2001 -> standards, standards, standards

13. read/write standard io