Created
February 2, 2017 21:20
-
-
Save dstd/338d55a739a911703381cbeeb7c63695 to your computer and use it in GitHub Desktop.
Bash function to get correctly-cased path from case insensitive value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_path_true_case() | |
{ | |
local C_PATH="/" | |
local C="" | |
local OLD_IFS="$IFS" | |
IFS=/ | |
for C in $1; do | |
if [ "$C_PATH" = "/" ]; then | |
C_PATH=`find "$C_PATH" -maxdepth 1 -type d -ipath "$C_PATH$C"` | |
else | |
C_PATH=`find "$C_PATH" -maxdepth 1 -type d -ipath "$C_PATH/$C"` | |
fi | |
if [ "$C_PATH" = "" ]; then | |
C_PATH="" | |
break | |
fi | |
done; | |
IFS="$OLD_IFS" | |
echo "$C_PATH" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment