4 ms·
POSIX shell scripting is just broken. Don't get me wrong. I love doing it, but from a language design point it is abysmal. Just this week I tried to write a sc
by arendtio 3y ago
POSIX shell scripting is just broken. Don't get me wrong. I love doing it, but from a language design point it is abysmal.
Just this week I tried to write a script to apply a custom function to a list of files. But the amount of time you spend just to make sure it works with special cases like spaces or new line characters in file names is not healthy. After all, it is probably one of the most standard scenarios.
First, I thought I would use 'find -execdir' or 'find | xargs', but neither supports shell functions. So I went on to take the 'while read' road, just to learn, that POSIX 'read', does not support all options you would need to make that work with all special cases.
- JackSlateur 3y agoYou can xargs a bash function That function must be exported before, for instance: my_function(){ ... } export -f my_function find | xargs my_function
- arendtio 3y agoYeah, I know, but 'export -f' is not POSIX compliant [1]. In addition, I have read, that this solution has quite a bad performance [2]. 1: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_22 https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V... 2: https://stackoverflow.com/a/67780632/1149404 https://stackoverflow.com/a/67780632/1149404
- Night_Thastus 3y agoNot only broken, but every single implementation of it is broken in different ways - even between those that claim to be POSIX-compliant.