User Tools

Site Tools


redirection

If you want to send us your comments, please do so. Thanks
More on comments


Redirection and substitution

In bash
From the Advanced Bash-Scripting Guide:

Examples

ExampleExplanation
ls -l > ls-l.txtMove the output of ls -l to the file ls-l.txt
ls -l 1> ls-l.txtMove the output of ls -l to the file ls-l.txt
ls -l » ls-l.txtAppend the output of ls -l to the file ls-l.txt
ls -l 2> /dev/nullDo not display the error messages
grep da * > file.txt 2>&1Move the output of grep da * to file.txt and the error output too
ls -1 > /dev/null 2>&1Move the output and the error output of ls -1 to /dev/null (destroy all the output data and forget about it)
ls -1 &> /dev/nullIs shorthand for the previous command
ls -1 |& grep sometextSends standard output and error output to the next command's standard input
read string < <(some piped command with quotes)Process Substitution1)

File descriptors

Adding a & in front makes a number a file descriptor, like in &1

0stdin
1stdout
2stderr

/dev/null

/dev/null returns an end-of-line character. It can be shown by executing the command echo “`cat /dev/null`” in a bash shell

All about redirection
I/O Redirection
Bash-redirections cheat sheet
/dev/null
In the shell what does 2>&1 mean?


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2022 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
redirection.txt · Last modified: 03-12-2021 08:44 by wim