Interview Prep/Shell Scripting/Troubleshooting: tools, portability, permissions and environment

`comm -23 expected.txt installed.txt` prints `comm: file 1 is not in sorted order`, even though both files were produced with `sort`.

IntermediateTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer

Likely causes → The files were sorted under different locales (for example one on a laptop with en_US.UTF-8, one in cron with C), or with different options (sort -f). comm and join compare using the current locale's collation and detect the mismatch.

Diagnose →

locale | grep -E 'LC_COLLATE|LANG'
LC_ALL=C sort -c expected.txt; LC_ALL=C sort -c installed.txt    # -c checks order

Fix → Sort and compare under the same, explicit locale:

export LC_ALL=C
comm -23 <(sort -u expected.txt) <(sort -u installed.txt)

Prevent → Set LC_ALL=C (byte order, fast and stable) at the top of scripts that sort, compare or use character ranges like [a-z].

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: tools, portability, permissions and environment