You’ll have to be more specific how you created your output,
And what is the difference you’re concerned about between your correct and incorrect outputs… I see formatting and missing a couple partitions.
I do not see any partitions that are in one of the lists and missing in the other. Both have 30 entries.
Also I find that it is clear how the output is created. The commands are there to be seen.
To the OP.
I might be that what you see is not what you expected or wanted. That however does not mean it is “correct” or “wrong” as you call it.
I am not at all sure how the sequence is decided on. The first one has of course the dependency that partitions of a device are show after each device because of the “graphics”. I have no idea what decides the sequence of them. Is sda3 after sda2 because 3 comes after 2 in an ASCII sort, or because it is the next partition as defined in the partition tabel?
Also sda10 comes after sda9, which not an ASCII sort. this could point to partition label sequence and not alphabetical sequence.
In most cases partitions are in their numbered sequence in the partition table, but not always.
Also IMHO nv comes before sd in alphabetic, thus the main items in the first list are also not alphabetic.
You say it is correct, but I fail to see why. Any document you based that conclusion on?
In the second case I can not see any reason for why this is mixed up as it is, but that is of course also your concern.
As you mention you use this in a script, I want to cite (probably superfuous) from the man page:
The default output, as well as the default output from options like --fs and --topology, is subject to change. So whenever possible, you should avoid using default outputs in your scripts. Always explicitly define expected columns by using --output columns-list in environments where a stable output is required.
And while we are at the man page, there is no mentioning at all about a sequence of the devices or entries. Thus your claim to what is “correct” has no base. And isn’t your case solved by piping the output through sort?
lsblk enumerates devices reading /sys/block so devices are normally in directory order. It should collect partitions immediately before moving onto next device, so last two entries are certainly unexpected. Output of “ls -1U /sys/block” would be interesting.
And of course your claim that it should be in lexicographical order is solely based on what you think being “correct”. This thought has no base on anything in the man page.
But I am repeating myself, all of what I say in my last three posts is already in my earlier post. Just saying the same thing all over again is not very productive, so I stop with that.
The only thing I agree with you is that the second list is “strange”.