by floatingatoll · 8y ago · 0 comments
$ cat - > foo
#!/bin/bash
a="BCD"
[[ $a =~ .C. ]] && echo 1
[[ $a =~ ".C." ]] && echo 2
^D
$ bash foo
1
$ $ a=BCD; b=.C.; [[ $a =~ $b ]]; echo $?; [[ $a =~ "$b" ]]; echo $?
otherwise, interpolating variables in regular expressions as text would require other syntax (more confusing).also, "cat -" is redundant, use "cat". this behavior is specified by POSIX.