tags:

views:

23

answers:

2

How to overcome the case sensitivity while accessing a file in unix using shell script.?

I have a file namely file.txt in the designation path and in script while accessing the same file with the name FILE.txt it throws the error as Cannot open File.

Please guide me how to access the file with case change in unix scripting.

How to turn off case sensitivity in c shell.

+2  A: 

file names are case sensitive on Unix systems. As you might have at the same time file.txt and File.txt in the same directory, it is not safe to let a script consider a file name is good when it has not the same case. However, find can tell you:

let my_file="$( find . -iname 'FILE.txt' -maxdepth 1 | head -n 1 )"

(head) ensures you get ONLY one result.

Once again, don't do this, it is EVIL. Change your habits and get used to case sensitivity.

Benoit
+1  A: 

To turn off case sensitivity , in bash, you can use nocaseglob

shopt -s nocaseglob
echo FILE.txt
ghostdog74
How to turnoff case sensitivity in c shell?
Shashang