好奇,想知道为什么下面不工作的性质:+BASH =〜包含子: “+” 或正则表达式字符行为
人物“\”,“(”和“*”有道理即*将扩大到文件夹/文件在当前目录(命令行shell扩展时),同样\和(将希望关闭性格的工作,但我的理解是“+”应该像“ - ”一样工作。
PS:我知道在IF语句中放置双引号,即“$ {o}”,将适用于下面我测试用例中的所有字符。在带有或不带双引号的IF语句中使用\ $ {o}将会失败所有检查。
$ for o in - + \` ~ \~ , _ =/\\ ! @ \# $ \$ %^\& \* \(\); do a="a${o}b${o}c";if [[ $a =~ ${o} ]]; then echo "${o} exists in $a and =~ works"; else echo -e "\ncharacter ${o} doesn't work with =~\n"; fi; done
- exists in a-b-c and =~ works
character + doesn't work with =~
` exists in a`b`c and =~ works
/home/ubuntu exists in a/home/ubuntub/home/ubuntuc and =~ works
~ exists in a~b~c and =~ works
, exists in a,b,c and =~ works
_ exists in a_b_c and =~ works
= exists in a=b=c and =~ works
/exists in a/b/c and =~ works
character \ doesn't work with =~
! exists in a!b!c and =~ works
@ exists in [email protected]@c and =~ works
# exists in a#b#c and =~ works
$ exists in a$b$c and =~ works
$ exists in a$b$c and =~ works
% exists in a%b%c and =~ works
^ exists in a^b^c and =~ works
& exists in a&b&c and =~ works
character * doesn't work with =~
character (doesn't work with =~
) exists in a)b)c and =~ works
没有'*'不扩展到文件列表 - 在正则表达式中,它意味着“零或多个前面的标记”。 –
@CharlesDuffy正确,我的意思是“for”声明。 –
......但是你为'for'语句转义为'\ *',所以它没有在那里做任何这样的替换。 –