教科书告诉我,用bash进行正则表达式比较,用如下方式:
if [[ "$1" =~ '^[[:space:]]*#' ]]
然而将同样语句移植到cygwin中会发生死活认不出的情况。研究了一下,将语句作如下修改:
if [[ $1 =~ ^[[:space:]]*# ]]
即可。
原因如下:
In bash 3.2, the [[ ]] quoting rules changed slightly. Since [[ already
introduces special quoting rules, single quotes are not required; the
regex is already protected by the shell from globbing.