agraja.wordpress.com

Suppress Error Message in Shell Script

In Linux, Shell on August 7, 2007 at 2:52 pm

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
  1. igpJ6c fw831f64td9glse934dkjga

  2. Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  3. 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