Autosave: 2022-12-11 19:00:05
This commit is contained in:
		
							parent
							
								
									45920ddaba
								
							
						
					
					
						commit
						06e81d5a09
					
				
					 3 changed files with 15 additions and 0 deletions
				
			
		| 
						 | 
					@ -18,6 +18,12 @@ This is a redirection statement. It is redirecting data to the `null` device on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The `2>&1` argument is the content: any errors that the program may generate and try to show in stout. Notice we are using the [file descriptors](/Programming_Languages/Shell/File_descriptors_and_redirection.md) `1` and `2`.
 | 
					The `2>&1` argument is the content: any errors that the program may generate and try to show in stout. Notice we are using the [file descriptors](/Programming_Languages/Shell/File_descriptors_and_redirection.md) `1` and `2`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you just want the errors regardless of whether they appear in `stdout` you do:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					[some_command] > /dev/null 2>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Example
 | 
					## Example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
I have used this in my Mongo start-up script:
 | 
					I have used this in my Mongo start-up script:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,12 @@ It is common practice to combine redirection with the [file descriptors](/Progra
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Redirecting inputs
 | 
					## Redirecting inputs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					We can also switch the direction of the redirection symbol and pass in a file to a command rather than command ouput to a file:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					sql-processing-program < data.sql
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Appending 
 | 
					## Appending 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
We use `>>` to append contents on the next available line of a pre-existing file. Continuing on from the example above:
 | 
					We use `>>` to append contents on the next available line of a pre-existing file. Continuing on from the example above:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								_scripts/random_revision_topic.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								_scripts/random_revision_topic.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					find / -type f > list_of_files.list
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue