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?
bash append overwrite io-redirection
add a comment |
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?
bash append overwrite io-redirection
1
Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of usingset -o noclobberand then using>!extravagantly; that defeats the objective.
– Jonathan Leffler
Nov 10 at 17:32
1
noclobberis 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
add a comment |
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?
bash append overwrite io-redirection
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
bash append overwrite io-redirection
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 usingset -o noclobberand then using>!extravagantly; that defeats the objective.
– Jonathan Leffler
Nov 10 at 17:32
1
noclobberis 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
add a comment |
1
Practice, more practice, and yet more practice — and don't write I/O redirections without thinking what you mean. Beware of usingset -o noclobberand then using>!extravagantly; that defeats the objective.
– Jonathan Leffler
Nov 10 at 17:32
1
noclobberis 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
add a comment |
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!
1
You might note that if you havenoclobberset, 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 useunset noclobber; echo 456 > xyz; set -o noclobber, but you can also useecho 456 >! xyz. Be cautious though — if you find yourself routinely writing>!, then thenoclobberreally isn't helping and you need to think accurately when working.
– Jonathan Leffler
Nov 10 at 17:31
add a comment |
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!
1
You might note that if you havenoclobberset, 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 useunset noclobber; echo 456 > xyz; set -o noclobber, but you can also useecho 456 >! xyz. Be cautious though — if you find yourself routinely writing>!, then thenoclobberreally isn't helping and you need to think accurately when working.
– Jonathan Leffler
Nov 10 at 17:31
add a comment |
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!
1
You might note that if you havenoclobberset, 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 useunset noclobber; echo 456 > xyz; set -o noclobber, but you can also useecho 456 >! xyz. Be cautious though — if you find yourself routinely writing>!, then thenoclobberreally isn't helping and you need to think accurately when working.
– Jonathan Leffler
Nov 10 at 17:31
add a comment |
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!
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!
answered Nov 10 at 17:23
Patrick Stetz
10016
10016
1
You might note that if you havenoclobberset, 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 useunset noclobber; echo 456 > xyz; set -o noclobber, but you can also useecho 456 >! xyz. Be cautious though — if you find yourself routinely writing>!, then thenoclobberreally isn't helping and you need to think accurately when working.
– Jonathan Leffler
Nov 10 at 17:31
add a comment |
1
You might note that if you havenoclobberset, 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 useunset noclobber; echo 456 > xyz; set -o noclobber, but you can also useecho 456 >! xyz. Be cautious though — if you find yourself routinely writing>!, then thenoclobberreally 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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 noclobberand then using>!extravagantly; that defeats the objective.– Jonathan Leffler
Nov 10 at 17:32
1
noclobberis 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