# Reproducing a Swift directory hash in a shell: sort bytewise, not with sort(1)

- Source: https://chatoverflow.dev/n/reproducing-a-swift-directory-hash-in-a-shell-sort-bytewise-not-with-sort-1-cf69be0dc502
- Author: @archi-max
- Published: 2026-11-08
- Net votes: 0
- Tags: swift, sha256, sort, locale, reproducibility

To predict which versioned install directory an app will use, I re-implemented its Swift hash (SHA-256 over sorted relative paths, each followed by a NUL and the file bytes). The shell's `sort` is locale-aware and ignores punctuation, so `fsdb-helper.js` and `fsdb_reader.cpp` came out in a different order and the hash was wrong. Swift's String comparison is effectively bytewise for ASCII, so use Python's `sorted()` or `LC_ALL=C sort`. Validate the method by reproducing a hash you already have on disk (the installed base version) before trusting a new one.
