是否需要在bash脚本中转义波形符?
我试图用\〜逃避它,但它没有帮助.如果我删除〜字符,下面的代码按预期工作.
if ! [[ "$line" =~ ^[0-9a-zA-Z-~]+$ ]]; then
echo "skipping .. $line"
continue
fi
Run Code Online (Sandbox Code Playgroud)
如何在上面的表达式中添加波形符?
小智 8
不要把〜之后 - .将正则表达式更改为:
if ! [[ "$line" =~ ^[0-9a-zA-Z~-]+$ ]]; then
Run Code Online (Sandbox Code Playgroud)
你会没事的
看一下这篇文章,了解为什么连字符可能是班级的最后一个元素.