5 ms·
This is priceless. Countless times I have learned -- then later forgotten -- to use "$@" ... especially in cygwin's Windows 'spaces in filenames' territory
by HocusLocus 7y ago
This is priceless. Countless times I have learned -- then later forgotten -- to use "$@" ... especially in cygwin's Windows 'spaces in filenames' territory
- orev 7y agoAt this point in time (i.e. 21st century), any *nix script or program that doesn’t handle spaces in files names is woefully buggy. Maybe 20 years ago this was excusable, but not now. Spaces can reasonably be expected to be in filenames in all systems. Support for other “special” characters in filenames (e.g. newlines), however, could still be debatable.
- enriquto 7y ago> any *nix script or program that doesn’t handle spaces in files names is woefully buggy. On the contrary! It is filesystems that support plain spaces in filenames that are broken. Filenames are variable names. Allowing separators in them is bonkers. I make a point of carefully crafting my scripts to wreak havoc whenever a user has spaces in their filenames.
- anoncake 7y agoGREATI~1.DEA
- michaelmrose 7y agoFile names are an interface used by normal people to name files. Teaching everyone to name their files differently seems unlikely to succeed. There is no particular reason your shell can't distinguish between a space inside a filename and the space between tokens in output. The fact that you have to do anything at all yourself is a bug.
- enriquto 7y ago> File names are an interface used by normal people to name files. Teaching everyone to name their files differently seems unlikely to succeed. Sure. But there's no reason why typing the spacebar on a GUI to input your filename should produce a file with a plain space on the filesystem. It could be a unicode non-breaking space, for example.
- anoncake 7y agoThat would just make working with files programmatically harder. The issue isn't that file names contain spaces but that we use programming languages that use spaces to separate fields/entries instead of proper data structures.
- enriquto 7y agoDo these languages allow spaces in their variable names? Filenames are the variable names of shell scripting.
- oalae5niMiel7qu 7y agoWrong. Shell scripts have actual variables. They start with $. Filenames are one possible value you might store in these variables.
- DonHopkins 7y agoFunny how you just say these things as if they were true, without them being true, or any evidence. If you want to be pedantic, Unix has ALWAYS allowed ANY character in file names, except for "/" (unless you have a GatorBox). You once said: "Raw spaces in filenames are an abomination that make shell scripting unnecessarily difficult." No, bash is an abomination that makes shell scripting unnecessarily difficult. Prohibiting spaces in file names seems to be an obsession with you. (How about tabs? ;) You've said you don't see why people should be able to name their files anything they want, and that your reason for prohibiting billions of people from doing what they want is to make your bash scripts simpler. Then simply don't use bash, instead of trying to change the world. Read what I replied to you when you said that 7 months ago, and tell me if the world has changed so much since then that you're right this time around: https://news.ycombinator.com/item?id=19952668 https://news.ycombinator.com/item?id=19952668 Slash is the ONLY character you're not allowed to have under Unix. There are no good reasons to disallow spaces. Disallowing characters in file names that you're allowed to have solves absolutely no problems, it only causes them. There used to be a bug in the Gatorbox Mac Localtalk-to-Ethernet NFS bridge that could somehow trick Unix into putting slashes into file names via NFS, and Unix would totally shit itself when that happened. That was because Macs at the time (1991 or so) allowed you to use slashes (and spaces of course, but not colons), and of course those silly Mac people, being touchy feely humans instead of hard core nerds, would dare to name files with dates like "My Spreadsheet 01/02/1991". https://en.wikipedia.org/wiki/GatorBox https://en.wikipedia.org/wiki/GatorBox I just tried to create a file name on the Mac in Finder with a slash in it, and it actually let me! But Emacs dired says it actually ended up with a ":" in it. So then I tried to create a file name with a colon in it, and Finder said: "Try using a name with fewer characters or with no punctuation marks." Must be backwards compatibility for all those old Mac files with slashes in their name. Go figure! If you think nobody would ever want to use a space or a slash in a file name, then you should get out more often and talk to real people in the real world. There are more of them than you seem to believe!
- DonHopkins 7y agoFunny how he would criticize users who want to use spaces in their file names, instead of shells that make it practically impossible for programmers to support spaces in file names.
- thanatropism 7y agoWat
- deleted 7y ago[deleted]
- StillBored 7y agoI might say that allowing spaces (newlines, quotes, asterisk , and various other "control" characters) in the filenames is the real bug. Sure its cool that you can put anything you want in a filename, but do you really need them? Particularly on a command line oriented OS? If the entire OS's experience was windows explorer style interactions or C binary strings like manipulation then fine. This causes nothing but problems, all to avoid a simple character filter.. https://www.tecmint.com/manage-linux-filenames-with-special-characters/ https://www.tecmint.com/manage-linux-filenames-with-special-... See how many "errors" you can find in that article. There are a bunch, consider the touch *, example if your using rm...
- joshuaissac 7y agoA space is a completely normal character that users quite reasonably expect to be able to have in filenames. Treating it as a regular character is not a bug. There are lots of Linux programs that can deal with spaces in filenames already.
- orev 7y agoAt this point that ship has already sailed. And it’s really not that unreasonable for users to want to be able to use what is available to them on the keyboard.
- kortex 7y agoI really wish there were a "lexical space" (spacebar) and "semantic space" (shift-space or some other control). Use something less obtrusive for the semantic space than - or _, like the interpunct ·. It breaks visually/semantically but is lexically part of the same string. this·is·variable·one Vs one two three Now I just use an ergodox ez (qmk-driven) keyboard with _ in an easy spot and snake_case everything but people says it's "ugly" or some bs (camelCase, especially with initialisms, drives me nuts).
- Izkata 7y agoSpace (%20) and non-breaking space (%A0). People do somehow type the second one into web forms regularly enough (resulting in strange error messages) that those two hex codes are embedded in my brain.
- Sharlin 7y agoIt just seems that the shell semantics (and to an extend those of other Unix tools) are specifically designed to strip off a level of quoting/escaping and perform word splitting the moment you lose your focus for a bit if you're even aware of all the arcane rules in the first place.
- orev 7y agoI totally agree. Dealing with shell semantics to support spaces is definitely a special type of arcane wizardry. At least using newer constructs like arrays can help.