54 days ago · Tech · hide · Fediverse post

Globs sort filenames character by character, so numbered files often come out in a surprising order, with 10 before 2. Zsh has a neat fix for this: the n glob qualifier, which applies a “natural” sort, treating any run of digits as a number rather than a string of characters. I found this feature useful when building a PDF from multiple files.n I exported my multi-page document from Inkscape to one PNG per page, named Page 1.png, Page 2.png, and so on. I then stitched them into a single PDF with ImageMagick: $ magick *.png document.pdf But when I opened document.pdf, the pages were jumbled: page 10 came straight after page 1. That made no sense! To debug, I checked what the glob expanded to, using print -l to print each match on its own line: $ print -l *.png Page 1.png Page 10.png Page 11.png Page 12.png Page 2.png Page 3.png ... There it was: Page 10.png came before Page 2.png, because the character 1 sorts before 2. Adding the n glob qualifier makes Zsh sort numbers by their…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town