Case_insensitive search

Case_insensitive search

am 19.12.2007 12:19:16 von Christian Christmann

Hi,

in a bash script (actually configure.in) I have to set a variable
to a path name.

However, depending on the system configuration, the
path might be written in lower cases or use also upper
cases.

Currently I'm doing:
MYVAR=/path_name

so, the other possibility /path_Name will not be found.

What's the best way to search for a path name
in a non case-sensitive manner?

What I need is something like
MYVAR=case_insensitive(/path_name)

Thank you.

Tim

Re: Case_insensitive search

am 19.12.2007 12:48:58 von Andrew Smallshaw

On 2007-12-19, Tim Frink wrote:
>
> in a bash script (actually configure.in) I have to set a variable
> to a path name.
>
> However, depending on the system configuration, the
> path might be written in lower cases or use also upper
> cases.
>
> Currently I'm doing:
> MYVAR=/path_name
>
> so, the other possibility /path_Name will not be found.
>
> What's the best way to search for a path name
> in a non case-sensitive manner?

Since you're using bash:

shopt -s nocaseglob

--
Andrew Smallshaw
andrews@sdf.lonestar.org

Re: Case_insensitive search

am 19.12.2007 12:52:11 von Stephane CHAZELAS

On Wed, 19 Dec 2007 12:19:16 +0100, Tim Frink wrote:
> Hi,
>
> in a bash script (actually configure.in) I have to set a variable
> to a path name.
>
> However, depending on the system configuration, the
> path might be written in lower cases or use also upper
> cases.
>
> Currently I'm doing:
> MYVAR=/path_name
>
> so, the other possibility /path_Name will not be found.
>
> What's the best way to search for a path name
> in a non case-sensitive manner?
>
> What I need is something like
> MYVAR=case_insensitive(/path_name)
[...]

You mean you want to find the list of existing path that match
/path/to/some/dir case insensitively?

You could do something like

set /[pP][aA][tT][hH]/[tT][oO]/[sS][oO][mM][eE]/[dD][iI][rR]
for i
do
[ -d "$i" ] && set "$@" "$i"
shift
done
if [ "$#" -gt 1 ]; then
echo >&2 "more than one dir match"
exit 1
fi
if [ "$#" -eq 0 ]; then
echo >&2 "no matching dir"
exit 1
fi

Note that [ -d, returns true both for directories and symlinks
to directories.

--
Stephane

Re: Case_insensitive search

am 19.12.2007 12:57:05 von PK

Tim Frink wrote:

> Hi,
>
> in a bash script (actually configure.in) I have to set a variable
> to a path name.
>
> However, depending on the system configuration, the
> path might be written in lower cases or use also upper
> cases.
>
> Currently I'm doing:
> MYVAR=/path_name
>
> so, the other possibility /path_Name will not be found.
>
> What's the best way to search for a path name
> in a non case-sensitive manner?
>
> What I need is something like
> MYVAR=case_insensitive(/path_name)

Put that way, you can't do that. MYVAR must have a definite value, not many
at once. What you can do is check for the existence
of /path_name, /path_Name, etc. When you have determined the one that
actually exists, then you assign that to MYVAR.

Re: Case_insensitive search

am 19.12.2007 20:44:23 von Rikishi 42

On 2007-12-19, Tim Frink wrote:
> in a bash script (actually configure.in) I have to set a variable
> to a path name.
>
> However, depending on the system configuration, the
> path might be written in lower cases or use also upper
> cases.
>
> Currently I'm doing:
> MYVAR=/path_name
>
> so, the other possibility /path_Name will not be found.
>
> What's the best way to search for a path name
> in a non case-sensitive manner?
>
> What I need is something like
> MYVAR=case_insensitive(/path_name)
Can't help you with that. But find can return the existing path to you, no
matter what case you use in your variable.

find start_dir/ -type d -iname "$MYVAR"

There are, of course, parameters to limit to which depth it'll search, and
such.


--
There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
Douglas Adams