2 ms·
"... Since 'cat > foo.py' erases foo.py, you are obviously lying about that error message. ..." True this syntax erases the file. But all I did was cut+paste t
by bootload 19y ago
"... Since 'cat > foo.py' erases foo.py, you are obviously lying about that error message. ..."
True this syntax erases the file. But all I did was cut+paste the example from the original source & added the source code encoding on posting. I knew the example code missed the encoding and I checked the example text for extra unicode characters (another possible source of errors) as I saved to the file & checked with cat. So I tried the example on the CLI before I posted and overlooked the redirection. It's not worth lying, way too many sharp people to pick you up. Just a simple display mistake.
Btw, the inference I'm lying. Does that also apply to the original author as well?
"... Some time later ..."
Doing a bit of digging. It appears the 'cat > foo.py' works like this ...
"... Redirection of output causes the file whose name results from the expansion of word to be opened for writing on file descriptor n , or the standard output (file descriptor 1) if n is not specified. If the file does not exist it is created; if it does exist it is truncated to zero size. ..." [0]
So my theory is you have tried this with a full file & it has erased itself. Thanks for the pick-up though. It is a fine distinction and something I've not come across before. We are both right but at different times.
[0] http://www.wlug.org.nz/bash%281%29Part5 http://www.wlug.org.nz/bash%281%29Part5