Skip to content

Instantly share code, notes, and snippets.

@dstd
Created February 2, 2017 21:20
Show Gist options
  • Save dstd/338d55a739a911703381cbeeb7c63695 to your computer and use it in GitHub Desktop.
Save dstd/338d55a739a911703381cbeeb7c63695 to your computer and use it in GitHub Desktop.
Bash function to get correctly-cased path from case insensitive value
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