diff --git a/Programming_Languages/Shell/File_descriptors.md b/Programming_Languages/Shell/File_descriptors.md index 543f3af..e05a486 100644 --- a/Programming_Languages/Shell/File_descriptors.md +++ b/Programming_Languages/Shell/File_descriptors.md @@ -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. diff --git a/Programming_Languages/Shell/Redirection.md b/Programming_Languages/Shell/Redirection.md index 62a5080..4b1f8bc 100644 --- a/Programming_Languages/Shell/Redirection.md +++ b/Programming_Languages/Shell/Redirection.md @@ -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: