2>&1 /dev/null 
Author Message
 2>&1 /dev/null

I'm working on a script, and the problem i'm
 having is that I'm trying to set the DEBUG="2>&1
 /dev/null" to throw stdout and stderr to /dev/null
 but rpm keeps interpreting it as files to
 (un)install. here's an example.

 #!/bin/sh
 DEBUG="2>&1 /dev/null"
 rpm -e director-db $DEBUG

 I've tried all sorts of things. different quoting
 and what not. there has to be a way to do this,
 possibly a way to redirect stderr to /dev/null for
 the life of the script. i still want my echo
 statements to go to stdout. i could add this line
 by line, and it works, but i need to turn this off
 at a moments notice, hence the variable. maybe i'm
 going about this all wrong?

Sent via Deja.com
http://www.*-*-*.com/



Wed, 16 Jul 2003 02:06:30 GMT  
 2>&1 /dev/null

Quote:

> I'm working on a script, and the problem i'm
>  having is that I'm trying to set the DEBUG="2>&1
>  /dev/null" to throw stdout and stderr to /dev/null
>  but rpm keeps interpreting it as files to
>  (un)install. here's an example.
>  #!/bin/sh
>  DEBUG="2>&1 /dev/null"
>  rpm -e director-db $DEBUG
>  I've tried all sorts of things. different quoting
>  and what not. there has to be a way to do this,
>  possibly a way to redirect stderr to /dev/null for
>  the life of the script. i still want my echo
>  statements to go to stdout. i could add this line
>  by line, and it works, but i need to turn this off
>  at a moments notice, hence the variable. maybe i'm
>  going about this all wrong?

DEBUG="2>&1 /dev/null"
eval rpm -e director-db $DEBUG

What is not commonly understood is that there are _two_ "stages"
of parsing a shell construct: "stripping out" variable assignment
lists and redirection operators, and everything else generally
understood to be the normal process of interpreting a command line.

By the time variable substitution, filename substitution, command
substitution, word separation, etcetera, occurs, redirection
operators are long gone; if they are "retained" by variable
substitution there will be no context left to understand them as
redirection operators. Use "eval" to "modify" this order of evaluation.

-Brian



Wed, 16 Jul 2003 03:43:46 GMT  
 2>&1 /dev/null

Quote:


> >  DEBUG="2>&1 /dev/null"
> >  rpm -e director-db $DEBUG
> DEBUG="2>&1 /dev/null"
> eval rpm -e director-db $DEBUG

I don't think you tried this, as there are still two errors lurking:
there is a missing redirection, and the ordering is wrong.  This
version does what the original poster asked for.

    DEBUG=">/dev/null 2>&1"
    eval rpm -e director-db $DEBUG

In passing, I will point out that in my experience tossing away
standard error is evil.  Of course, it's fine for a one-off, but if
this is going into a script, or a cron entry I strongly recommend
taking the extra time to record the unwanted output somewhere.

Tim.
--
Tim Goodwin   | "Not ideal, I grant you, but life's
Leicester, UK | like that." -- Ian Batten



Sun, 20 Jul 2003 00:46:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Expect & closing /dev/null

2. Expect: abort upon printing to /dev/null??

3. null strings with Python<->C++ via ILU<->VisiBroker

4. Socket<->Modem<->Null-modem?

5. Exclude Nulls (in Key definition): what is Null?

6. Null Record is not always Null

7. NULL statements, NULL values, and teaching

8. win32com support for NULL bstr, NULL com object

9. /dev/mary.had.a.little.lamb ( more stupid /dev/hft tricks )

10. HELP>>>>>>>Fortran-Pascal Linking

11. >>>>>>>FROM SMTK TO C++

12. NULL Character & CLACom

 

 
Powered by phpBB® Forum Software