Suppose we have a script named test_sort in our $PATH with the following contents:
#!/bin/bash
function echo_text () {
printf -- "%s\n" "$fc$oc$fs$lc"
printf -- "%s\n" "$fc$fs$oc$lc"
}
# first character
fc="$1"
# last character
lc="$2"
# other character
oc="$3"
# field separator
fs="$4"
echo_text | LC_ALL sort -t "$fs"
It prints out two lines which have the share the same first and last characters, but the positions of the field separator and the "other" character swap between them.
If we run test_sort a b y x, we get the following output:
axyb
ayxb
The fourth argument, x is used as the field separator. If we swap it for a character with a higher, such as z, we would run test_sort a b y z, giving us:
ayzb
azyb
It makes no sense. If the outputs of each invocation were passed through sed "s/[xz]/_/g, the lines are ordered differently. After normalizing the field separators, test_sort a b y x and test_sort a b y z should produce identical outputs. Instead, the order changes based on whether the field separator's character code is higher or lower than the field separator's. ay should always be coming after a because that's how alphabetical sorting of two words, where one only differs from the other by having additional letters appended to it, works. Tim comes before Timothy. The field separator is being included in the comparison!
Is GNU find supposed to be acting like this? Is there anyway to make it act the way I expect it should?
find(mentioned at the end) have to do with anything? Also, your invocation ofsortseems to be prefixed byLC_ALLin a way that makesLC_ALLthe command andsortan argument to that command.sortwhat fields to use (e.g. with-k 1,1 -k 2,2), it's using the whole line as the sort key. That would not avoid using the field delimiter as a sorting character. You get the same behaviour with the default field delimiter. I'm sure this has been asked before...... LC_ALL=_something_ sort ...?