手動增加本地詞典 01#!/bin/sh02 03 # spelldict.sh -- 使用'aspell'特性以及一些過濾以便04 # 允許命令列拼字檢查給定的輸入檔案05 06 # 不可避免的,你會發現,有些詞彙是錯誤的,但你認為07 # 它們是正確的。簡單的將它們儲存在一個檔案中,一次08 # 一行,並且確定變數'okaywords'指向這個檔案。09 10 okaywords="$HOME/okaywords"11 tempout="/tmp/spell.tmp.$$"12 spell="aspell" # 根據需要修改13 14 trap "/bin/rm -f $tempout" EXIT15 16 if [ -z "$1" ]; then17 echo "Usage: spell file | URL" >&218 exit 119 elif [ ! -f $okaywords ]; then20 echo "No personal dictionary found. Create one and return this command." >&221 echo "Your dictionary file: $okaywords" >&222 exit 123 fi24 25 for filename26 do27 $spell -a < $filename | \28 grep -v '@(#)' | sed "s/\'//g" | \29 awk '{if(length($0) > 15 && length($2) > 2) print $2}' | \30 grep -vif $okaywords | \31 grep '[[:lower:]]' | grep -v '[[:digit:]]' | sort -u | \32 sed 's/^/ /' > $tempout33 34 if [ -s $tempout ]; then35 sed 's/^/${filename}: /' $tempout36 fi37 done38 39 exit 0運行指令碼:這個指令碼需要在命令列上提供一個或多個檔案名稱 運行結果: 01首先,一個空的個人字典,txt內容摘錄自愛麗絲漫遊記:02$ spelldict ragged.txt03ragged.txt: herrself04ragged.txt: teacups05ragged.txt: Gryphon06ragged.txt: clamour07 08有兩個詞拼錯了,所以準備用echo命令把它們加到okaywords檔案中:09 10$ echo "Gryphon" >> ~/.okaywords11$ echo "teacups" >> ~/.okaywords12 13擴充了詞典檔案後的檢查結果如下:14 15$ spelldict ragged.txt16ragged.txt: herrself17ragged.txt: clamour