I'd like to write a bash script that execute the files in a directory in sorted name order. Specifically, the name order is by en_US.utf8
.
For example, if the dir /mydir
has the following files:
a1.txt
a2.txt
b1.txt
c1.txt
I have a function like this:
show_content() {
for f in "$@"; do
echo $f
cat $f
done
}
and run it by
show_content /mydir/*
How can I improve the code to make sure that the show_content
function execute these files in /mydir
the name order? How to specify if I want it to follow en_US.utf8
?
Is there a way to ensure that the en_US.utf8
is just effective for this bash script? Per @CharlesDuffy and @oguzismail's answer that we can change the setting for LC_COLLATE
to en_US.utf8
, but could it be done more "locally" without touching the global settings?