> -----Original Message----- > From: Paolo Bonzini <[email protected]> > Sent: Friday, November 21, 2025 15:41 > > The script is designed to be cross-platform > > Sure but it's not broken, just less effective, and the optimization is > actually > quite common. I have just checked and it's in all of GNU coreutils, FreeBSD, > OpenBSD, NetBSD. Rust uutils does not do it for stdin, though. > > > There is no guarantee that this optimization will be present on all > > potential > platforms. > > OTOH, it is virtually guaranteed that `ls' will always `stat()' the > > file. It would seem prudent to avoid potential pitfalls. > > Parsing the output of "ls" is also a potential pitfall. In particular, I am > not sure > what happens if $image_file has a newline. Maybe this is better: > > ls -Hdog "$1" | { > read ls_ign1 ls_ign2 ls_size ls_rest > echo $ls_size > }
You are right, I forgot about this case. A perhaps simpler solution is to use `ls -Hdogq', which replaces non-printing characters (including newline) in the filename with a `?'.
