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.
hfollowed by a vowel. Second command looks forhfollowed by your list of letters.his not a predefined function but is part of the regular expression to match against.h[aeiou]matches a pair of letters, the left letter beinghand 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].