Hi,
I'm using an 'if' statement to check whether one of positional arguments is a word or a construction like "x-y", but something doesn't seem right.
Here is the relevant part of the code:
Code:
if [[ "$3" =~ [a-Z]\-[a-Z] || "$3" =~ [a-Z] ]]; then
grepRange=$3; else grepRange=$4
fi
And for the input like this:
Code:
bash -x script --list free fornax
it outputs this:
Code:
+ [[ fornax =~ [a-Z]-[a-Z] ]]
+ [[ fornax =~ [a-Z] ]]
+ grepRange=fornax
but shouldn't the
$grepRange variable be blank in this case?
Bash version is 4.1.7(1)
Is there something I'm missing? Enclosing regexp in quotes or double quotes doesn't help.
Thanks in advance.