Autosave: 2022-12-11 18:30:05
This commit is contained in:
parent
0ac3ce7a48
commit
45920ddaba
2 changed files with 10 additions and 2 deletions
|
@ -17,4 +17,4 @@ File descriptors are shorthand for `stdin`, `stdout` and `stderr`:
|
|||
|
||||
They are typically used when you want to redirect the output of the standard/input /output/error somewhere, e.g a file or as input to another program. A classic case is `[some_command] > /dev/null 2>&1`
|
||||
|
||||
They are all technically "files" which are open and which append themselves to every process that can run in the shell. For any command or program that you run, you will be able to access `0`, `1` and `2` for them.
|
||||
They are all technically "files" which are open and which append themselves to every process that can run in the shell. For any command or program that you run, you will be able to access `0`, `1` and `2` for them. In this way they are similar to variables like [`$0`](/Programming_Languages/Shell/Passing_arguments_to_scripts.md#passing-arguments) and [`$@`](/Programming_Languages/Shell/Passing_arguments_to_scripts.md#passing-arguments). They have a universal meaning within the context of the shell runtime.
|
||||
|
|
|
@ -7,13 +7,21 @@ tags:
|
|||
|
||||
# Redirection
|
||||
|
||||
## Redirecting outputs
|
||||
The symbol `>` is called the **redirection operator** because it redirects the output of a command to another location. You most frequently use this when you want to save contents to a file rather than standard output.
|
||||
|
||||
```bash
|
||||
ls | grep d* > result.txt
|
||||
```
|
||||
|
||||
## Appending operator
|
||||
### Combining redirection with file descriptors
|
||||
|
||||
It is common practice to combine redirection with the [file descriptors](/Programming_Languages/Shell/File_descriptors.md) to redirect the output of `stdout` and `stderr`. A common case is to [redirect error output to `/dev/null`](/Programming_Languages/Shell/Redirect_to_dev_null.md).
|
||||
|
||||
|
||||
## Redirecting inputs
|
||||
|
||||
## Appending
|
||||
|
||||
We use `>>` to append contents on the next available line of a pre-existing file. Continuing on from the example above:
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue