Writing a script for aspell

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    The scirpt I have is meant to check the strings read in from a file with the aspell subroutine in the UNIX bash shell. I don't seem to have a problem reading it and checking it. Only printing it correctly.

I'm having some trouble with my script/understanding it fully. I want to print out all of the items stored in uncorrect in the mispelled columns I have set under the mispelled table. Then print out the values corrected with user input. Am I not storing them correctly? Or am I not calling them correctly in my last echo statement? I'm really just lost for syntax. Forgive me I'm new at this and am just having trouble understanding it. Thanks so much for your help in advance.

  1. Relevant commands, code, scripts, algorithms:
    It was recommended in my assignment that we use the ASPELL LIST command, but I didn't know how to properly implement it.

  2. The attempts at a solution (include all code and scripts):

#! /bin/bash

#empty array's created to store the new spelling and old ones.
reSpell=()
uncorrect=()
# now check the spellings
let count=1

check=(`aspell list -p ~/.checked < $1`)
# for each mispelled word in the file is entered into i and put into the new directory memory if corrected
for i in ${check
[*]} ; do
   uncorrect[$count]=$i
   read -p "$i is mispelled. Press \"Enter\" to keep this spelling or type your new spelling here: " newSpell

   # unfixed spellings are ignored and not replaced and are left where they are in the fiexedspell array
if [ "$newSpell"="" ]; then
   echo $i>> ~/.memory

else
   reSpell[$count]=$newSpell
fi
   count+=1
   echo ""

done


printf "MISPELLED %20s\n" CORRECTIONS
echo ""
let counter=1
for i in ${reSpell
[*]}; do

   echo "{uncorrect[$counter]} %-20s%s\n" "${reSpell[$counter]}"

   counter+=1
done

NIU, Dekalb, Il , Ege, CSCI330

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Use printf in lieu of echo .

And, you may want to use sh like

for (( i=0; i<${#reSpell
[*]}; i++))

to loop through all the elements.

Thanks so much, that makes much more sense. However, I'm still getting the same problems. I've tried multiple different variants of my loop. It seems to me that I may be storing it wrong? Maybe I am still trying to loop through the arrays wrong but here's what else I tried and has only accessed the first string of misspelled words. (Along with this one.)

for i in "${uncorrect[@]}"; do
for j in "${reSpell[@]}"; do
printf $i "" $j 

This did not access the strings I believe I stored in the corresponding arrays, so maybe my problem is storage. Thanks again.

#! /bin/bash

reSpell=()
uncorrect=()
# now check the spellings
let count=1

check=(`aspell list -p ~/.checked < $1`)
# for each mispelled word in the file is entered into i and put into the new directory memory if corrected
for i in ${check
[*]} ; do
   uncorrect[$count]=$i
   read -p "$i is mispelled. Press \"Enter\" to keep this spelling or type your new spelling here: " newSpell

   # unfixed spellings are ignored and not replaced and are left where they are in the fiexedspell array
if [ "$newSpell"="" ]; then
   echo $i>> ~/.memory

else
   reSpell[$count]=$newSpell
fi
   count=$((count+1))
   echo ""

done


printf "MISPELLED %20s\n" CORRECTIONS
echo ""
for (( i=0; i<${#uncorrect
[*]}; i++));  do
printf "${uncorrect[$i]} %-20s%s\n" ${reSpell[$i]}

done

Not sure if your respell array is correctly and completely populated, but you should at least get a list of uncorrect's elements with

printf "%20s  %20s\n\n" "MISPELLED","CORRECTIONS"
for (( i=0; i<${#uncorrect
[*]}; i++))
   do printf "%20s  %20s\n" ${uncorrect[$i]}, ${reSpell[$i]}
   done

And, bash array by default start at element 0. That's why I started with i=0. Consider that for your count variable.