Oddbean new post about | logout
 @e7491467

Small optimization, if I may: add "--null" to tar and instead of the "-d" option with xargs, use "-0". 
 @2ad00f7c @e7491467 That rhymes nicely with my earlier claim that is near impossible to write resilient shell code, handle errors properly or  maintain the result. Use python, or maybe ruby…

Hat does shellxheck have to say to that onliner? Does it find the “weird file names” problem? 
 @e7491467 

I am somewhat disappointed.

@2ad00f7c

https://assets.chaos.social/media_attachments/files/111/061/486/151/496/000/original/8e8be906d58e94aa.png 
 @e7491467 @2ad00f7c 

"Why did you not post that earlier?"

I was on a phone. I don't like posting code, any code, that I can't test.

I am posting this now, with screenshots instead of code in the post, because I have written and tested this. I sometimes forget to test the code examples I post, but I am trying not to.

"Why are you nagging about this stuff?"

I think that shell is dangerous and I see a lot of recommendations for shellcheck, "learn to write bash" courses and similar. Don't. 
 @e7491467 @2ad00f7c 

Use shells interactively.

Learn to use the shell-like things in proper programming languages.

Try to script in this.

Try to also use simple tooling such as Pythons shutil, pathlib, tarfile, zipfile and so on even in interactive use so you become fluent.

I know I am annoying as fuck. It's for your own good. Twice, if you teach others. 
 @e7491467 @2ad00f7c 

Also, I fucked up. For this specific use-case it should be 

for name in names:
  Path(name).unlink(missingok=True)

If there isn't, it should be in a try-except just for correctness. Without it there is a very theoretical (given your use-case) race condition. 
 @87c98d39 @e7491467 @2ad00f7c Um.

Going back to the *problem*, untarring in the wrong directory, neither code is necessarily good.

1. Where you did this, there is an entry "foo".
2. The tarball contains an entry "foo".

If you overwrote "foo", your original file is lost. If you didn't, you'll lose it after deleting all entries contained in the tarball. 
 @70281677 @e7491467 @2ad00f7c 

Yeah, the actual solution is to ask time machine stat.