我想要顯示正好具有14,15和16個唯一字母的字的數量。我想要使用for循環。 (它必須是一個襯墊。)在grep中使用的Linux終端命令行變量
這是我到目前爲止有:
for i in {14..16}; do echo "There are $(cat /usr/share/dict/dutch | grep -P '^.{"$i"}$' | grep -vP -c '(.).*\1') words with exactly $i unique letters"; done
結果:
There are 0 words with exactly 14 unique letters
There are 0 words with exactly 15 unique letters
There are 0 words with exactly 16 unique letters
這意味着環作品,當我這樣運行它:
echo "There are $(cat /usr/share/dict/dutch | grep -P '^.{14}$' | grep -vP -c '(.).*\1') words with exactly 14 unique letters" && echo "There are $(cat /usr/share/dict/dutch | grep -P '^.{15}$' | grep -vP -c '(.).*\1') words with exactly 15 unique letters" && echo "There are $(cat /usr/share/dict/dutch | grep -P '^.{16}$' | grep -vP -c '(.).*\1') words with exactly 16 unique letters"
的結果是:
There are 13 words with exactly 14 unique letters
There are 2 words with exactly 15 unique letters
There are 0 words with exactly 16 unique letters
這表明,我做錯了什麼用的grep命令裏面的變量($ I)。我不知道我該怎麼做或解決這個問題。
在此先感謝
你得雙雙引號引號 – JNevill
雙引號中的雙引號實際上包裹在$()子shell中,因此它們不會導致問題。 –