Unusual behaviour of linux's sort command

前端 未结 2 495
孤独总比滥情好
孤独总比滥情好 2021-01-23 04:47

On Linux shell the result of echo -e \"arrays2 2\\narrays 2\\narrays3 2\" | sort is

arrays  2
arrays2 2
arrays3 2

and the result

2条回答
  •  [愿得一人]
    2021-01-23 05:13

    The behaviour is locale-dependent:

    echo -e "arrays2 28\narrays 28\narrays3 28" | LANG=C sort
    

    prints

    arrays 28
    arrays2 28
    arrays3 28
    

    While

    echo -e "arrays2 28\narrays 28\narrays3 28" | LANG=de_DE.UTF-8 sort
    

    prints

    arrays2 28
    arrays 28
    arrays3 28
    

    (Note that the locale must be installed for this to have this effect, if the locale doesn't exist, the behaviour will be the same as with LANG=C).

提交回复
热议问题