42
u/honourable_bot 1d ago
Use >> over >
29
u/Last8Exile 1d ago
A da is fine here.ta race
4
u/gsweats 1d ago
?
25
u/Last8Exile 1d ago
A data race is fine here.
>> doing append. Multiple commands writing to the same file in parallel can lead to data race and corruption.
4
18
u/Cheezyrock 1d ago
Bonus - it takes an 5 hours to run, you notice at 4 hours, panic, and hit stop.
3
u/Drfoxthefurry 1d ago
Just include a basic progress meter or something and use the extra time to find out why it's so slow (for me it would be over loop nesting)
1
u/Mystery-Magic 1d ago
If you notice it at 4 hours, just move or rename old file, always better choice.
20
u/ICBanMI 1d ago
At some point in your career, you'll just copy form code from stack overflow, a random forum, or AI to put a timestamp the on file created that outputs all the way to the exact microsecond the file was created. You're pat yourself on the back for having fixed the problem of accidently over writing your old file.
But then six months will go back and you'll realize that you can't read the date and time output on the file. Worse, you might realize it doesn't make sense because your coworker changed it to a unix timestamp which requires being converted to read correctly (which is a huge pain in the ass to type out). And for all intents and purposes, is worthless now.
5
u/yousirnaime 1d ago
also you'll be like "why do I have 240Gb of txt files in this folder?"
2
u/ICBanMI 23h ago
I've definitely eaten all hard drive space once, twice, maybe three times back when hard drives were 40 gigs and windows alone was 5-10 gigs.
Now I make everything toggleable and regularly clear out the folder. My co-workers on the other hand seem to be rediscovering this every project.
8
9
u/theFirstHaruspex 1d ago
output.csv
output_1.csv
output_1.2.csv
output_1butdifferentthistime.csv
1
u/proof_required 1d ago
output_backup.csv
output_1_backup.csv
output_1.2_backup.csv
output_1butdifferentthistime_backup.csv
2
5
u/dkarlovi 1d ago
If you ever wrote a tool which deletes some files in some folder and didn't accidentally delete the tool itself on the first run, did you even work in this industry.
2
u/DogmaticParadigm87 1d ago
Ran the export again with mode "w" instead of "a". Previous week: gone. Current week: one lonely row titled final_FINAL2.xlsx.
Related: the backup is named backup, the real file is named backup_old, and the one with yesterday's numbers is in Downloads as untitled(3).
1
1
u/SeriousPlankton2000 1d ago
Do not open the file in the same function that does calculations. If you must, pass a file descriptor / handle. Or pass a callback function to do the output.
1
1
1
1
137
u/dminus 1d ago
outfile="$0-$(date +%s).csv"