This is my midterm example questions. However, I don't know how to write code in bash yet properly.. Please can you help by explaining to me? This is very important to me.
Thank you
答案 0 :(得分:1)
If I have understood your question... this should work:
$ ls /usr/bin | cut -b1 | uniq -c
please note this will count everything under /usr/bin (files, links,...)
答案 1 :(得分:1)
这可能符合您的要求。它基本上将所有命令存储在名为“命令”的数组中。此数组已根据{{ whichItem.id1.subCategories['subCategory'] }}
进行排序。然后我们循环遍历该数组中的所有元素,并使用ls
提取每个单词的第一个字母,并将其存储在一个跟踪我们正在处理的当前“字母”的变量中。随着循环继续,只要字母相同,我们继续增加计数器,否则,我们打印出字母和计数器,存储新的当前字母并将计数器重置为1(因为它已经是新字母)。最后,我们需要打印最后一条记录,从而在循环外打印。
${cmd:0:1}