我想要显示正好具有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中,因此它们不会导致问题。 –