Accidents with `echo >` and `echo >>`











up vote
1
down vote

favorite












Today I learned the distinction between echo > and echo >> when I overwrote my log file. I don't trust myself and know I'll make this mistake again unless I make this idiot proof. Is there a way to do this?










share|improve this question




















  • 1




    Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of using set -o noclobber and then using >! extravagantly; that defeats the objective.
    – Jonathan Leffler
    Nov 10 at 17:32








  • 1




    noclobber is a way, but it might cause bigger accidents in the future: When you trust the safety belt in your own environment and want to help a colleague (or on another system or as root), you start overwriting files again.
    – Walter A
    Nov 10 at 21:32















up vote
1
down vote

favorite












Today I learned the distinction between echo > and echo >> when I overwrote my log file. I don't trust myself and know I'll make this mistake again unless I make this idiot proof. Is there a way to do this?










share|improve this question




















  • 1




    Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of using set -o noclobber and then using >! extravagantly; that defeats the objective.
    – Jonathan Leffler
    Nov 10 at 17:32








  • 1




    noclobber is a way, but it might cause bigger accidents in the future: When you trust the safety belt in your own environment and want to help a colleague (or on another system or as root), you start overwriting files again.
    – Walter A
    Nov 10 at 21:32













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Today I learned the distinction between echo > and echo >> when I overwrote my log file. I don't trust myself and know I'll make this mistake again unless I make this idiot proof. Is there a way to do this?










share|improve this question















Today I learned the distinction between echo > and echo >> when I overwrote my log file. I don't trust myself and know I'll make this mistake again unless I make this idiot proof. Is there a way to do this?







bash append overwrite io-redirection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 17:50









Cyrus

44.2k43375




44.2k43375










asked Nov 10 at 17:23









Patrick Stetz

10016




10016








  • 1




    Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of using set -o noclobber and then using >! extravagantly; that defeats the objective.
    – Jonathan Leffler
    Nov 10 at 17:32








  • 1




    noclobber is a way, but it might cause bigger accidents in the future: When you trust the safety belt in your own environment and want to help a colleague (or on another system or as root), you start overwriting files again.
    – Walter A
    Nov 10 at 21:32














  • 1




    Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of using set -o noclobber and then using >! extravagantly; that defeats the objective.
    – Jonathan Leffler
    Nov 10 at 17:32








  • 1




    noclobber is a way, but it might cause bigger accidents in the future: When you trust the safety belt in your own environment and want to help a colleague (or on another system or as root), you start overwriting files again.
    – Walter A
    Nov 10 at 21:32








1




1




Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of using set -o noclobber and then using >! extravagantly; that defeats the objective.
– Jonathan Leffler
Nov 10 at 17:32






Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of using set -o noclobber and then using >! extravagantly; that defeats the objective.
– Jonathan Leffler
Nov 10 at 17:32






1




1




noclobber is a way, but it might cause bigger accidents in the future: When you trust the safety belt in your own environment and want to help a colleague (or on another system or as root), you start overwriting files again.
– Walter A
Nov 10 at 21:32




noclobber is a way, but it might cause bigger accidents in the future: When you trust the safety belt in your own environment and want to help a colleague (or on another system or as root), you start overwriting files again.
– Walter A
Nov 10 at 21:32












1 Answer
1






active

oldest

votes

















up vote
4
down vote













Open your ~/.bashrc file and put set -o noclobber at the end.



Now whenever echo > is called on an existing file, the file will not be overwritten and an error will appear saying: -bash: FILENAME: cannot overwrite existing file.



Remember to do source ~/.bashrc for these changes to take effect!






share|improve this answer

















  • 1




    You might note that if you have noclobber set, doing "echo 123 > xyz; echo 456 > xyz" will generate an error on the second, as intended. However, sometimes you need to override it. Obviously, you can use unset noclobber; echo 456 > xyz; set -o noclobber, but you can also use echo 456 >! xyz. Be cautious though — if you find yourself routinely writing >!, then the noclobber really isn't helping and you need to think accurately when working.
    – Jonathan Leffler
    Nov 10 at 17:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241516%2faccidents-with-echo-and-echo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













Open your ~/.bashrc file and put set -o noclobber at the end.



Now whenever echo > is called on an existing file, the file will not be overwritten and an error will appear saying: -bash: FILENAME: cannot overwrite existing file.



Remember to do source ~/.bashrc for these changes to take effect!






share|improve this answer

















  • 1




    You might note that if you have noclobber set, doing "echo 123 > xyz; echo 456 > xyz" will generate an error on the second, as intended. However, sometimes you need to override it. Obviously, you can use unset noclobber; echo 456 > xyz; set -o noclobber, but you can also use echo 456 >! xyz. Be cautious though — if you find yourself routinely writing >!, then the noclobber really isn't helping and you need to think accurately when working.
    – Jonathan Leffler
    Nov 10 at 17:31















up vote
4
down vote













Open your ~/.bashrc file and put set -o noclobber at the end.



Now whenever echo > is called on an existing file, the file will not be overwritten and an error will appear saying: -bash: FILENAME: cannot overwrite existing file.



Remember to do source ~/.bashrc for these changes to take effect!






share|improve this answer

















  • 1




    You might note that if you have noclobber set, doing "echo 123 > xyz; echo 456 > xyz" will generate an error on the second, as intended. However, sometimes you need to override it. Obviously, you can use unset noclobber; echo 456 > xyz; set -o noclobber, but you can also use echo 456 >! xyz. Be cautious though — if you find yourself routinely writing >!, then the noclobber really isn't helping and you need to think accurately when working.
    – Jonathan Leffler
    Nov 10 at 17:31













up vote
4
down vote










up vote
4
down vote









Open your ~/.bashrc file and put set -o noclobber at the end.



Now whenever echo > is called on an existing file, the file will not be overwritten and an error will appear saying: -bash: FILENAME: cannot overwrite existing file.



Remember to do source ~/.bashrc for these changes to take effect!






share|improve this answer












Open your ~/.bashrc file and put set -o noclobber at the end.



Now whenever echo > is called on an existing file, the file will not be overwritten and an error will appear saying: -bash: FILENAME: cannot overwrite existing file.



Remember to do source ~/.bashrc for these changes to take effect!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 17:23









Patrick Stetz

10016




10016








  • 1




    You might note that if you have noclobber set, doing "echo 123 > xyz; echo 456 > xyz" will generate an error on the second, as intended. However, sometimes you need to override it. Obviously, you can use unset noclobber; echo 456 > xyz; set -o noclobber, but you can also use echo 456 >! xyz. Be cautious though — if you find yourself routinely writing >!, then the noclobber really isn't helping and you need to think accurately when working.
    – Jonathan Leffler
    Nov 10 at 17:31














  • 1




    You might note that if you have noclobber set, doing "echo 123 > xyz; echo 456 > xyz" will generate an error on the second, as intended. However, sometimes you need to override it. Obviously, you can use unset noclobber; echo 456 > xyz; set -o noclobber, but you can also use echo 456 >! xyz. Be cautious though — if you find yourself routinely writing >!, then the noclobber really isn't helping and you need to think accurately when working.
    – Jonathan Leffler
    Nov 10 at 17:31








1




1




You might note that if you have noclobber set, doing "echo 123 > xyz; echo 456 > xyz" will generate an error on the second, as intended. However, sometimes you need to override it. Obviously, you can use unset noclobber; echo 456 > xyz; set -o noclobber, but you can also use echo 456 >! xyz. Be cautious though — if you find yourself routinely writing >!, then the noclobber really isn't helping and you need to think accurately when working.
– Jonathan Leffler
Nov 10 at 17:31




You might note that if you have noclobber set, doing "echo 123 > xyz; echo 456 > xyz" will generate an error on the second, as intended. However, sometimes you need to override it. Obviously, you can use unset noclobber; echo 456 > xyz; set -o noclobber, but you can also use echo 456 >! xyz. Be cautious though — if you find yourself routinely writing >!, then the noclobber really isn't helping and you need to think accurately when working.
– Jonathan Leffler
Nov 10 at 17:31


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241516%2faccidents-with-echo-and-echo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."