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!

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

  2. on 16 Nov 2017 at 1:41 pm Lorri

    Great items from you, man. I have take into account your stuff prior to and you’re just
    too wonderful. I actually like what you’ve bought here, really like
    what you are saying and the best way through which you say it.

    You’re making it enjoyable and you continue to care for to sty it
    sensible. I can’t wait to learn much more from you.
    This is actualoy a wonderful website.

  3. on 24 Sep 2018 at 3:20 pm Tilly

    Greqt post. I was checking continuousl this
    blog and I am impressed! Very userful information particularly the last part :
    ) I care forr such information much. I was looking for this
    certan information for a long time. Thank you and best of luck.

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

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