:: Re: [dyne:bolic] A short lesson on …
Startseite
Nachricht löschen
Nachricht beantworten
Autor: stomfisite
Datum:  
To: dynebolic mailinglist
Alte Treads: Re: [dyne:bolic] my nvidia module
Betreff: Re: [dyne:bolic] A short lesson on redirecting error messages
David Wood wrote:

>
> It's creating dirs that are already there to make sure
> it can put the
> driver components in the right places -I need to add
> something to these
> lines in the rc script so that it checks first to
> make this a little
> more elegant (still a n00b with linux scripting!).
> What it does now
> isn't harmful though.
>


If you add 2> /dev/null to the end of your mkdir line this will send
any error messages to the bottomless pit and you wont have to
bother about doing a [ -x dir_name ] test.

2 is the file descriptor of the standard error messages. 2>
/dev/null is handy in shell scripts when you only want to echo a
variable to another process and the command gives you error output
which confuses the issue.

A better way is to redirect both error and standard messages in case
your successful command gives you unwanted status information.

2>&1 duplicates the standard error as the standard output so both
can be processed at once.

The order of redirection in this case is important depending what
you want. The correct way to get rid of all messages is:

> /dev/null 2>&1


Try this yourself with
ls non_existant_file_name 2>&1 /dev/null
and you will get an error message
whereas
ls non_existant_file_name > /dev/null 2>&1
doesn't give one.

This is because redirection operators may precede or appear anywhere 
within a simple command or may follow a command, and redirections 
      are processed by the shell from left to right in the order 
they appear.


Thus the first command directs only the standard output to /dev/null
because the standard error was duplicated as standard output before
the standard output was redirected.

Instead of /dev/null you can capture the output to a local file if
you want to see what it says.

Hope that is clear so far.

A shorthand way of saying
>/dev/null 2>&1

is
&>/dev/null

Have fun
Stomfi