为什么以下bash脚本只打印输出变量?
#! /bin/bash foo=baaz regex='ba{2}z' if [[ $foo =~ 'ba{2}z' ]]; then echo "literal worked" fi if [[ $foo =~ $regex ]]; then echo "variable worked" fi
你不再需要bash正则表达式的引号:
#! /bin/bash foo=baaz regex='ba{2}z' if [[ $foo =~ ba{2}z ]]; then echo "literal worked" fi if [[ $foo =~ $regex ]]; then echo "variable worked" fi # Should output literal worked,then variable worked
我不记得哪个版本改变了这个.