好奇,想知道爲什麼下面不工作的性質:+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'語句轉義爲'\ *',所以它沒有在那裏做任何這樣的替換。 –