📄 letter-count.sh
字号:
#!/bin/bash# letter-count.sh: Counting letter occurrences in a text file.# Written by Stefano Palmeri.# Used in ABS Guide with permission.# Slightly modified by document author.MINARGS=2 # Script requires at least two arguments.E_BADARGS=65FILE=$1let LETTERS=$#-1 # How many letters specified (as command-line args). # (Subtract 1 from number of command line args.)show_help(){ echo echo Usage: `basename $0` file letters echo Note: `basename $0` arguments are case sensitive. echo Example: `basename $0` foobar.txt G n U L i N U x. echo}# Checks number of arguments.if [ $# -lt $MINARGS ]; then echo echo "Not enough arguments." echo show_help exit $E_BADARGSfi # Checks if file exists.if [ ! -f $FILE ]; then echo "File \"$FILE\" does not exist." exit $E_BADARGSfi# Counts letter occurrences .for n in `seq $LETTERS`; do shift if [[ `echo -n "$1" | wc -c` -eq 1 ]]; then # Checks arg. echo "$1" -\> `cat $FILE | tr -cd "$1" | wc -c` # Counting. else echo "$1 is not a single char." fi doneexit $?# This script has exactly the same functionality as letter-count2.sh,#+ but executes faster.# Why?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -