[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Have Bash to do case insensitive operation on test
From: |
Budi |
Subject: |
Re: Have Bash to do case insensitive operation on test |
Date: |
Wed, 14 Apr 2021 09:48:29 +0000 |
>> How to have Bash to do case insensitive operation on test:
>>
>> $ n=Foo
>> $ [ -e "$n" ] && echo $n exist
>>
>> foo exist
>> if it is:
>>
>> $ ls
>> foo bar baz
>
>
> Bash is able to do case-insensitive globbing, but the code that you
> posted does not use globbing at all. This doesn't stop us from
> performing a glob match though.
>
> shopt -s nocaseglob nullglob extglob
>
> set -- *("$n")
> if [ -e "$1" ]; then
> printf 'at least one name matches *(%s)\n' "$n"
> fi
>
> The *(...) globbing pattern is an extended globbing pattern borrowed
> from the ksh shell, enabled with the extglob shell option, and it would
> match zero or more names from the given |-delimited list of patterns
> (only one pattern is used here, from the string in $n).
>
> The nullglob shell option makes sure that the pattern is removed if
> there are no matches (not really needed here), and nocaseglob is for
> doing case-insenitive globbing.
>
> --
> Andreas (Kusalananda) Kähäri
> SciLifeLab, NBIS, ICM
> Uppsala University, Sweden
>
> .
THANKS
great answer