4 ms·
One of the best things (in my opinion) shells could have done is do newline separated filenames instead of spaces, which would make filenames with spaces much e
by CJefferson 6y ago
One of the best things (in my opinion) shells could have done is do newline separated filenames instead of spaces, which would make filenames with spaces much easier to handle (you can have newlines in filenames, but in this magic world let's ban those).
- enriquto 6y agoThat would pose problems also. The real solution, with no need to magic as you say, is to disallow spaces at the filesystem level (just like slashes and the null character are forbidden). For users typing filenames, this shouldn't be a problem, as those can be encoded e.g., as unicode's non-breaking space. Using space as a separator is a very important power, that other programming languages share. In what other programming language can you put spaces in variable names? In the shell, filenames are variable names! It is only natural that a space cannot appear inside a filename (but of course, most other unicode characters can).
- CJefferson 6y agoThis would require filenames became valid utf-8. This would be a good thing to do nowadays, irritatingly (having tried handling Unix filenames as utf 8 in the past), surprisingly many users have non-utf8 filenames.
- a1369209993 6y ago> This would require filenames became valid utf-8. No, it wouldn't; you'd just get EINVAL if you pass a filename containing "\x20" to open or other syscalls. If a application wants to use "\xC2\xA0" in a filename, it can do that, or it can not do that, same as currently. Same applies if it wants to use, say, "\xAA\xFF".
- jodrellblank 6y ago> In what other programming language can you put spaces in variable names? PowerShell; although you have to use long form to do it: PS C:\> ${var with spaces} = 1 PS C:\> Get-Variable *space* Name Value ---- ----- var with spaces 1 PS C:\> ${var with spaces} + 2 3
- layer8 6y ago> In what other programming language can you put spaces in variable names? In SQL, notably. Such identifiers need to be quoted, of course.
- dafoex 6y agoI totally agree that file names shouldn't have spaces because they are variables, and I (usually) name all my files with camelBackNotation names as I was taught is best practice for variable names. That said, with every command I remember running, treating the file name like a string - e.g. "file name.png" - has worked whenever I encounter spaces, no escape characters required.
- CJefferson 6y agoThe problem is shell is when I want to write something like 'find . | grep namepiece | xargs rm', or something like that. I can work around this by piling everything into the find, or in some cases by liberally spreading -0s around, but neither feel very "shell-like" to me.
- enriquto 6y agoThus it seems that a filesystem that forbade spaces in its filenames would solve your problems with the shell? Sounds good to me!
- dragonwriter 6y ago> In what other programming language can you put spaces in variable names? ISTR that many dynamic languages allow this with dynamic assignment features, but you often need to use similar dynamic access functiona rather than simple variable access to access them. Ruby also allows whitespace if it is unicode but not ASCII whitespace, without use of dynamic assignment/access methods. SQL allows spaces in object names but requires quoting, similar to shell.
- Serow225 6y agoYou can have spaces in F# variable names and functions :)
- lock-free 6y agoI don't see a functional difference in denying spaces in paths from denying new lines in paths. My dream OS would forbid path names that don't match \w in grep.
- chubot 6y agoOil fixes this problem with QSN: http://www.oilshell.org/blog/2020/10/osh-features.html#safe-processing-of-user-supplied-data-like-filenames http://www.oilshell.org/blog/2020/10/osh-features.html#safe-... You can have newlines in filenames, but you can also pass binary data with \0 if you want (it's 8 bit clean). Or you can use read -0 for a NUL delimiter, and eventually length-prefixed blobs with netstrings. The way I now think of it is that Oil should have all 3 solutions to "the framing problem" in networking: delimiting, escaping, and length prefixing. So you can convert from one regime to the other by using shell.