I am new at unix, I'm trying to learn the bash language, and when I went to the "Testing expression", I found this one:
[[ "whatever" =~ h[aeiou] ]]
I already read the answer to this question, so I understand what the operator =~ does. After running the previous command, the output of echo $?
is 0
, meaning the condition inside the [[ ]]
is met. If instead I type
[[ "whatever" =~ h[sdfghjkl] ]]
the output of echo $?
is 1
, so the condition was not met.
So, I would like to know what the h[aeiou]
and h[sdfghjkl]
are.
Is h
a predefined function inside the [[ ]]
expression? And if so, what is it doing? If not, what h[aeiou]
and h{sdfghjkl]
actually are?
Thanks.
h
followed by a vowel. Second command looks forh
followed by your list of letters.h
is not a predefined function but is part of the regular expression to match against. – doneal24 Oct 11 '22 at 20:33h[aeiou]
matches a pair of letters, the left letter beingh
and the right-hand letter being one of those listed between[
and]
(an English vowel letter).h[sdfghjkl]
is exactly the same, but with matching the right-hand letter with a list of different letters between[
and]
. – Sotto Voce Oct 11 '22 at 20:33