4 ms·
.. which falls over as soon as you have a file with a space in the name. Edit: this highlights the big weakness in the "UNIX philosophy", in which the only rec
by pjc50 7y ago
.. which falls over as soon as you have a file with a space in the name.
Edit: this highlights the big weakness in the "UNIX philosophy", in which the only record delimiter that's conventionally recognized in pipelines is the newline but the shell recognizes characters as filename delimiters that are also allowed in filenames. Causing a cascade of delimiter bugs. Sometimes you really do need a bit more structure to your data.
(The UNIX philosophy is best understood in contrast to what went before - the COBOL or JCL style where files had fixed records, in turn based on fixed-column punchcard layouts.)
- sxldier 7y agoIt's easy to unsafely handle filenames. I've seen it at my job where we do a lot of bash scripting. However, there are good guides on doing it the right way. [0] [0] https://mywiki.wooledge.org/BashPitfalls#for_f_in_.24.28ls_.2A.mp3.29 https://mywiki.wooledge.org/BashPitfalls#for_f_in_.24.28ls_....
- felixfbecker 7y agoAnd that’s why PowerShell is awesome :)
- pjc50 7y agoPowershell falls over in the other direction: the objects flowing down the pipeline are "magic" and can't be serialised, or even necessarily inspected with normal tools. For most unix operations you can replace foo | sort with foo > file sort < file I like the idea of powershell, but every time I try to do something complicated with it I'm disappointed.
- majkinetor 7y agoThat is some serious BS. Objects can be serialized easily. $WhateverObject | Export-CliXml $WhateverObject = Import-CliXml whatever.xml Most of the time `>` also work. By the way, PowerShell serialization is by orders of magnitude better then anything *nix has to offer as you can use objects from other machine shell just like they exist on your local one. > I like the idea of powershell, but every time I try to do something complicated with it I'm disappointed. I did some very complicated things in PowerShell. For example, check out the script that maintains ~300 mainstream packages on Chocolatey up to date, all in few minutes with bunch of self maintenance features. You need to learn it, simple as that. https://gist.github.com/choco-bot/a14b1e5bfaf70839b338eb1ab7f8226f https://gist.github.com/choco-bot/a14b1e5bfaf70839b338eb1ab7...
- pjc50 7y agoI suppose this is a good demonstration of the best way of getting a right answer being to post a wrong one, as I spent a long time trying to work out how to do this last time I needed it.
- eequah9L 7y ago> .. which falls over as soon as you have a file with a space in the name. Yeah, spaces are nasty. find has -print0 and xargs has -0 to handle this gracefully, but one needs to know to use it.
- Annatar 7y ago-print0 is a GNUism and isn't portable. As stated previously, replacing '{}' with "{}" will handle spaces and most metacharacters just fine.
- Annatar 7y agoAll you have to do is replace the single with double quotation marks and my commands will handle spaces just fine.