Recent Changes - Search:

Basics

Languages

Tools

OS

Resources

PmWiki

pmwiki.org

edit SideBar

Function Outputs

In Bash, one can direct the output of a function to multiple destinations. By default, the output will be directed to the terminal, in two different channels: Standard Output (1) and Standard Error (2).

Directing the output to a file

function arguments > Path/to/File Note that this will create a new file or overwrite an existing file.

Changing output channels

function arguments 1>&2 This, for example, will redirect the standard output of the command to standard error.

Negating output

function arguments #>&- A special case of changing channels, this will redirect the # (any number, pick 1 for stdoutput) to nowhere, so you get rid of the output.

Preserving colour coding

Functions such as ls or grep have very useful colour coding, which, because of the implied --color=auto when calling them, gets lost when redirecting output through pipes or a script. However, it can be maintained by specifying --color (the equivalent of --color=always).

Edit - History - Print - Recent Changes - Search
Page last modified on February 09, 2018, at 01:14 PM