Search code examples
bashshellzsh

How to let bash/zsh glob case sensitive


Environment:

$ /usr/bin/zsh --version
zsh 5.5.1 (x86_64-redhat-linux-gnu)

$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

I want the glob result to be sorted in dictionary order (ASCII order) and be case-sensitive.

Current behavior:

# Both zsh and bash are the same
$ echo *
9.0 9.1 a.0 A.0 a.1 A.1

A.1 should be sorted after A.0.

Useless attempts:

# Both zsh and bash are the same
$ (LC_COLLATE=C; echo *)
9.0 9.1 a.0 A.0 a.1 A.1

# For zsh
$ (LC_COLLATE=C; echo *(on))
9.0 9.1 a.0 A.0 a.1 A.1

# For zsh
$ (LC_COLLATE=C; echo *(:o))
9.0 9.1 a.0 A.0 a.1 A.1

Solution

  • You must have LC_ALL set, try in bash:

    (unset LC_ALL; export LC_COLLATE=C; echo *)