0
發佈低於我的代碼,想知道如果我可以搜索一個陣列的比賽......或者,如果那裏有一種方法,我可以搜索參數的內部UNIX文件。有沒有一種方法來搜索參數的內部的整個陣列?
#!/bin/bash
# store words in file
cat $1 | ispell -l > file
# move words in file into array
array=($(< file))
# remove temp file
rm file
# move already checked words into array
checked=($(< .spelled))
# print out words & ask for corrections
for ((i=0; i<${#array[@]}; i++))
do
if [[ ! ${array[i]} = ${checked[@]} ]]; then
read -p "' ${array[i]} ' is mispelled. Press "Enter" to keep
this spelling, or type a correction here: " input
if [[ ! $input = "" ]]; then
correction[i]=$input
else
echo ${array[i]} >> .spelled
fi
fi
done
echo "MISPELLED: CORRECTIONS:"
for ((i=0; i<${#correction[@]}; i++))
do
echo ${array[i]} ${correction[i]}
done
否則,我需要寫一個for循環來檢查每個陣列指數之,然後以某種方式作出決定語句是否要經過環和打印/取輸入
目前尚不清楚你遇到問題的代碼的哪個部分。我建議你爲你正在嘗試做的事提供一些僞代碼。 – SiegeX 2011-04-05 23:36:54
看到一個更好的方法我的回答這裏 - > http://stackoverflow.com/questions/5542078/can-i-pipe-ispell-output-to-an-array/5559915#5559915讓你'ispell'數據無需臨時文件即可進入數組 – SiegeX 2011-04-05 23:46:02