Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a case insensitive for loop in shell scripting

I'm trying to make a loop to create directories and move files into those directories so that I can sort stuff alphabetically. Here's what I have:

for i in a b c d e f g h i j k l m n o p q r s t u v w x y z
    do
        mkdir $i
        mv -i $i*.* ./$i/
done
ls

The issue is that the mv command in this loop doesn't catch the uppercase file names, and I don't want to create directories for both upper and lower case file names. What's the solution? Or if you don't want to come right out and tell me the solution, where can I find it?

I've looked at a few things on google and I haven't found a solution that I could use. I'm relatively new to shell scripting, so please explain any solutions you may suggest so that I'll understand and don't have to ask a similar question later.

like image 215
Jonathan Avatar asked Feb 17 '23 00:02

Jonathan


1 Answers

In bash, you can use

shopt -s nocaseglob
like image 142
that other guy Avatar answered Mar 06 '23 02:03

that other guy