1205
Comment:
|
← Revision 5 as of 2012-09-27 12:53:11 ⇥
1167
|
Deletions are marked like this. | Additions are marked like this. |
Line 39: | Line 39: |
Just like setting unclobber, it is also possible to unset it so overwriting can take place using '>' redirection operator. | Just like setting noclobber, it is also possible to unset it so overwriting can take place using '>' redirection operator. |
Line 48: | Line 48: |
<<FullSearchCached(category:NoClobber:Redirection:Locking)>> | <<FullSearchCached(category:NoClobber)>> |
Line 51: | Line 51: |
CategoryCategory CategoryCategory CategoryCategory | CategoryShell CategoryBashguide |
Use of noclobber
When setting 'noclobber' overwriting the content of an existing file by the '>' redirection operator will not be possible. You might have typed '>' to redirect the output of a certain command to an existing file, while you intended to use '>>' redirection operator. This is where 'noclobber' comes in action, preventing you from accidentally deleting the content of the existing file.
How to use it
ls > list
Try setting noclobber
set -o noclobber
Try again
ls > list bash: list: cannot overwrite existing file
How to overwrite the file even with noclobber set
If you are determined to overwrite the file you can use the '>|' method. Thus
ls >| list
Unset noclobber
Just like setting noclobber, it is also possible to unset it so overwriting can take place using '>' redirection operator.
set +o noclobber
List of pages in this category: