4 ms·
I spent my entire career avoiding file paths with spaces in. On the very rare occasions I'm using an external dataset that includes them I'll make a copy with
by hereonout2 3y ago
I spent my entire career avoiding file paths with spaces in.
On the very rare occasions I'm using an external dataset that includes them I'll make a copy with renamed files using underscores.
If more junior team members produce files with spaces in their paths I quickly educate them in how problematic it can be.
It's pretty rare this is a problem for me or my team, perhaps we're lucky in what we work on though.
Thankfully I have never seen a file named "*" or "--".
- munificent 3y agoHaving to completely change the naming scheme you use for human-authored and human-read artifacts entirely to route around shitting, confusing escaping in a programming language is not a convincing selling point for that language. If you have a file whose contents are Shakespeare's "As You Like It", you should be able to name that file "As You Like It" without having to worry that the computer will vomit and die on it. We deserve better tools.
- ndsipa_pomu 3y agoI too often avoid spaces in filenames, but when writing scripts it's far better to ensure that you cope with them properly. The trick is to always quote your variables by default and then run shellcheck on your script so that it can flag up the corner cases where quoting acts to unquote the string. Of course, it'll also flag up a host of other possible issues which are well worth fixing or at least understanding why it's a possible issue. Another common footgun is not including a double dash ('--') at the end of command options so that the following filename won't be interpreted as an option when it begins with a dash.
- vram22 3y ago>Another common footgun is not including a double dash ('--') at the end of command options so that the following filename won't be interpreted as an option when it begins with a dash. Yes. And if you have a file name that begins with a dash, and you want to delete it, you can use this command: $ rm -- -filename where -filename is that file. Here, the -- (double dash) means "end of the command-line options", so any argument after that is treated as a non-option argument, in this case, a filename for rm to delete. This -- (double dash) works with many Unix commands. It was introduced relatively early on in Unix history, after the issue of filenames starting with a dash was found. Although it is more likely that you would want to rename the file, to remove the dash from the name.
- ndsipa_pomu 3y agoAnother way of working around the issue of filenames beginning with a dash is to just put "./" in front of it. That's not always useful in scripts though if you don't know whether the variable will be a relative or absolute filename (though you could check for that easily enough).
- throwaway858 3y agoIf you ever need to use GNU make (still a popular tool) then you will be glad that you kept a policy of avoiding spaces in file names. There are places in Makefiles where no amount of quoting will help you, and it simply cannot handle files with spaces. Yeah, this is a problem with the tool that should be fixed, but my understanding is that it will never be fixed because of architectural reasons. And it's a very popular, useful, and most importantly, ubiquitous tool. So this is another good reason to simply have a policy of banning filenames with spaces (and there are many more reasons).
- deadbunny 3y agoAn entire career without quoting. Weird.
- hereonout2 3y agoNobody said that