Feed on
Posts
Comments

to  send the standard output and standard error streams from your shell script somewhere, place the following at the top of your script:

#!/bin/bash

exec &>  output.file;

[the rest of your code]


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

One Response to “redirect stdout and stderr in a shell script”

  1. on 15 Mar 2009 at 8:24 pm Camille

    Something very helpful is to redirect stderr in stdin,
    so you can pipe to grep or whatever:

    zsh$ cat /foo 2>&1 | grep ‘No such file’
    cat: /foo: No such file or directory

    If you want to keep only stderr you can do :

    zsh$ cat /foo 2>&1 1> /dev/null | grep ‘No such file’
    cat: /foo: No such file or directory

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.