You’ll never guess what I learned from https://www.uninformativ.de/blog/postings/2023-11-19/0/POSTING-en.html. I’ve never seen for i do
in shell scripts. Turns out, that walks over all positional arguments. So I reckon my for i in "$@"; do
can now be shorter from now on. Very interesting in that detailled explanation to see all the – at least to me – inconsistent handling of semicolons and line breaks.
@lyse@lyse.isobeef.org Cool!
@lyse@lyse.isobeef.org Oops, I must confess that I didn’t check whether that’s POSIX or not. 😬 So, thanks for the link. 👍
It really is a shame that there’s no guarantee that a shebang of #!/bin/sh
enforces true and strict POSIX-conformity. This is all so fragile. 😞
(I think I first saw for i; do
in Shell-Skript Programmierung by Patrick Ditchen from 2008: German excerpt. They didn’t mention any restrictions on shell versions and I’ve been using it for ages. 😅 (I’m not too happy that the book uses for i in $*
as the default template instead of for i in "$@"
. The book doesn’t care too much about file names with spaces in them.))
@movq@www.uninformativ.de You’re good, it’s POSIX-compliant. ;-) I also was taught $*
first instead of "$@"
. Looks like a common thing. :-) Shell has just soooooo many quirks and inconsistencies, it is quite hard to master it. But we’ll never get rid of it.