FlipsideReality Once upon a time, in a land far far away…

18May/090

BASH case insensitive path checking. (effificently)

I needed to check some paths for files. I have a script that calls a copy function on some files that were previously mounted on a case insensitve system. I couldn't find anything, so instead of using `find -i` which would be a resource hog i wrote this: -

#!/bin/bash
old_IFS=$IFS
if ! [ -a $1 ]; then
	trypath=""
	path=""
	IFS=$'/'
	for i in $1; do
		trypath=$path$i"/"
		if [[ -a $trypath ]]; then
			path=$trypath
		else
			ipath=`ls "$path" | grep -i $i`
			path=$path$ipath"/"
		fi
	done
	echo "$path"
else
	echo "exists"
fi
IFS=$old_IFS
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)