Case_insensitive search

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
Christian Christmann [ Mi, 19 Dezember 2007 12:19 ] [ ID #1889967 ]

Re: Case_insensitive search

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.
PK [ Mi, 19 Dezember 2007 12:57 ] [ ID #1889968 ]

Re: Case_insensitive search

On 2007-12-19, Tim Frink <plfriko [at] yahoo.de> 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 [at] sdf.lonestar.org
Andrew Smallshaw [ Mi, 19 Dezember 2007 12:48 ] [ ID #1889969 ]

Re: Case_insensitive search

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 "$ [at] " "$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
Stephane CHAZELAS [ Mi, 19 Dezember 2007 12:52 ] [ ID #1889970 ]

Re: Case_insensitive search

On 2007-12-19, Tim Frink <plfriko [at] yahoo.de> 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
Rikishi 42 [ Mi, 19 Dezember 2007 20:44 ] [ ID #1889997 ]
Linux » comp.unix.shell » Case_insensitive search

Vorheriges Thema: calc capacity??
Nächstes Thema: Req: SQL Developer / DBA