Suppress Error Message in Shell Script

stderr

Redirect the output of stderr (descriptor 2) to /dev/null:

# save this file as testnull
# chmod 755 testnull
ls -garbage 2>/dev/null
# try ./testnull

Diagram below shows a demo

shell_error.JPG

Notice that

1) redirecting to /dev/null from command line has no effect

2) redirecting error from shell script works !!

stdout

[raja@AGRAJA ~] ls 1>file_list.txt
[raja@AGRAJA ~] ls > same_file_list.txt

This is the default option during redirecting output.

i.e “1>” and “>” mean the same.

stdin

[raja@AGRAJA ~] ls 0>empty_file
[raja@AGRAJA ~] ls

The above prints to standard terminal.

Note that “empty_file” will be emptied.

Redirect everything to file

Redirect all console output texts (stdout, stderr, stdlog …) to file

For sh shell 
at command line:
[raja@AGRAJA ~] make > & ! make.log
inside shell script:
illegal junk text as command > junk.spam 2>&1
[or]
illegal junk text as command > & ! junk.spam
For csh shell
Note: The below works on the command line, as well as inside a script
[raja@AGRAJA ~] make > & ! make.log
[raja@AGRAJA ~] ls > & ! files.lst
[raja@AGRAJA ~] illegal junk text as command > & ! junk.spam
Advertisements

4 thoughts on “Suppress Error Message in Shell Script

  1. Greetings
    In rare instances, men taking PDE5 inhibitors (oral erectile dysfunction medicine, including LEVITRA) reported a sudden decrease or loss of vision in one or both eyes, or a sudden loss or decrease in hearing, sometimes with ringing in the ears and dizziness. cheapest online
    Goodluck!!!
    ________________________________
    🙂 uk order

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s